如何在two.js中解释外部svg文件 [英] How can I interpret an extrenal svg file in two.js
本文介绍了如何在two.js中解释外部svg文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么办法可以解释two.js中带有对象标记的外部svg文件? 我尝试了以下方式,但是..
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
如果我可以导入一个外部.svg文件,那太好了,因为我的svg文件太大,无法以HTML形式作为内联SVG编写.
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.
谢谢.
推荐答案
可能是您需要在contentDocument中选择svg标记.例如:
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);
};
这篇关于如何在two.js中解释外部svg文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文