Cannot reference element of existing svg
There seems to be several ways of almost doing this. If I load the svg image with svg.js apparently I can access its elements by id. According to the docs I can get the same result using SVG.adopt but that requires an object reference. Using document.getElementById(), I can get the parent svg object but not an element within it. I'm trying this sort of thing but it's printing null each time.
ionViewDidLoad() {
let draw = document.getElementById("svg");
draw.addEventListener("load",function() {
let element = SVG.adopt(document.getElementById('element_0'));//I also tried SVG.get
console.log(element, document.getElementById('element_0'));
}, false);
}
I tried using console.log(draw.getElementsByClassName("segment")), having set the class name on an element to segment. I just got back an empty array.
Edit: This will work with inline SVG and the SVG.get('elementId'). I had been using:
<object id="svg" data="img.svg" type="image/svg+xml" width="100%"></object>
The question remains how do I load an svg from a file and subsequently manipulate it with svg.js?
链接地址: http://www.djcxy.com/p/64182.html上一篇: 你如何克服html表格嵌套限制?
下一篇: 无法引用现有svg的元素