问题
Is there any way I can interpret an external svg file with object tag in two.js? I tried in the way below but..
HTML
<object type="image/svg+xml" data="./svg/mydrawing.svg" id="mysvg"></object>
JS
var mySvg = document.getElementById("mysvg").contentDocument;
var shape = two.interpret(mySvg);
console.log(shape);
//in console:
Uncaught TypeError: Cannot call method 'toLowerCase' of undefined
It's nice if I can import an external .svg file as my svg file is too big to write in HTML as Inline SVG.
Thanks in advance.
回答1:
It could be that you need to select the svg tag within the contentDocument. For example:
var svgObject = document.getElementsByTagName('object')[0];
svgObject.onload = function(){
var mySvg = svgObject.contentDocument.getElementsByTagName('svg')[0];
var two = new Two();
var shape = two.interpret(mySvg);
console.log(shape);
};
来源:https://stackoverflow.com/questions/21720790/how-can-i-interpret-an-extrenal-svg-file-in-two-js