Snap SVG - Moving a loaded element around

蓝咒 提交于 2019-12-03 03:16:20

Set a transform on the butterfly. You want a translate transform to move it. E.g.

butterfly.transform("t100,100");

That syntax is the same as Raphael. But you can also use a Snap matrix

var t = new Snap.Matrix()
t.translate(100, 100);
butterfly.transform(t); 
anngelfra

The SVG Transform Attribute applies a list of transformations to an element and it's children (here's a very good tutorial on that: https://www.dashingd3js.com/svg-group-element-and-d3js). You can use different types of transformations; for example, as Totty asks, to move just to x=1 and y=1, you'd use

myElement.setAttribute('transform','translate(30,100)');

More information on that in this answer: How to manipulate translate transforms on a SVG element with javascript in chrome?. Once you read more you notice you could even use animations really easily with Snap:

myElement.animate({ transform:'translate(30,100)'}, 700, mina.bounce );
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!