如何在 snap.svg 中创建具有 id 属性的组元素?
我试图这样创建它:
gr = draw.g(t1,t2);
gr.id="BoundingBox-"+BBoxElementCounter;
或者
gr = draw.g(t1,t2);
gr.attr({"id": "BoundingBox-"+BBoxElementCounter});
但它不起作用。生成的 svg 代码没有 id 属性。
如何在 snap.svg 中创建具有 id 属性的组元素?
我试图这样创建它:
gr = draw.g(t1,t2);
gr.id="BoundingBox-"+BBoxElementCounter;
或者
gr = draw.g(t1,t2);
gr.attr({"id": "BoundingBox-"+BBoxElementCounter});
但它不起作用。生成的 svg 代码没有 id 属性。
g.attr({id:"gid"})
应该是正确的方法 - 你如何验证没有 id 出现?
下面的代码是在 Chrome JavaScript 控制台中输入的,并.outerSVG()
在 Elements 选项卡上验证使用和检查。
Snap.version
"0.2.0"
var g = s.g()
undefined
g.attr({id:"gid"})
Element {id: "Shq33m2ni13", node: g#gid, paper: Element, type: "g", anims: Object…}
g.outerSVG()
"<g id="gid"/>"
请注意,该版本是0.2.0
我从adobe-webplatform / Snap.svg GitHub 存储库中获得的。如果您必须使用0.1.0
,请查看将 ID 应用于使用未记录属性的 snap.svg 图形node
。
g.node.id = 'gid';