Domanda


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.

È stato utile?

Soluzione

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';
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top