문제


how I can create a group element with id attribute in snap.svg ?

I tried to create it like this:

gr = draw.g(t1,t2);
gr.id="BoundingBox-"+BBoxElementCounter;

or

gr = draw.g(t1,t2);
gr.attr({"id": "BoundingBox-"+BBoxElementCounter});

But it is not working. Generated svg code is without id attribute.

도움이 되었습니까?

해결책

g.attr({id:"gid"}) should be the correct way - how are you validating that no id appears?

The code below was typed in the Chrome JavaScript console and verifies using .outerSVG() as well as inspection on the Elements tab.

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"/>"

Notice that version is 0.2.0 which I got from the adobe-webplatform / Snap.svg GitHub repo. If you have to use 0.1.0, look at apply ID to a snap.svg graphic which uses the undocumented node property.

g.node.id = 'gid';
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top