benoît
benoît

Reputation: 1483

element toDefs and use with Snap.svg

I don't know how to create an element in <defs> and use it in svg.

I try something like :

var s = Snap('#drawing');
var c1 = s.circle(ww / 2, wh / 2, 100).attr('id','c1').toDefs(); // in <defs>

and after

var cc = c1.use(); // in defs not in svg root

Upvotes: 0

Views: 1402

Answers (1)

Ian
Ian

Reputation: 13852

That should roughly work, I've just appended as well, here is an example...

var s = Snap(800,800);

var c1 = s.circle(100,100, 100).attr('id','c1').toDefs(); // in <defs>
var cc = s.append( c1.use() );

test link

Make sure you also have the latest snap ver 0.3.0 as I think there was a bug with defs in the older ones.

I also did a page a while back for this here for Snap which may help a little to see it in use elsewhere.

Upvotes: 4

Related Questions