Snap SVG - Moving a loaded element around

MikO

I am trying to use Snap SVG library to move an element in an SVG graphic around the screen. This is the code of the element:

<g id="butterfly">
  <path id="wings" fill="#FFFFFF" stroke="#CFEA90" stroke-width="4" stroke-miterlimit="10" d="M139.741,74.038c-5.847-1.477-11.794,1.029-14.605,5.736c-0.463-5.791-5.095-10.963-11.275-12.115c-7.017-1.309-13.365,3.059-14.179,9.755c-0.654,5.381,2.469,10.622,7.36,13.155c-0.143,0.146-0.28,0.284-0.403,0.402c-3.157,3.055-2.81,7.082,0.777,8.994c3.586,1.912,9.053,0.985,12.211-2.071c0.836-0.809,1.773-2.517,2.632-4.62c-0.068,2.586,0.13,4.835,0.632,6.038c1.724,4.127,6.377,7.274,10.394,7.031c4.017-0.244,5.876-3.786,4.152-7.913c-0.067-0.16-0.14-0.343-0.215-0.538c5.45-0.264,10.315-3.753,11.775-8.957C150.814,82.459,146.669,75.79,139.741,74.038z"/>
  <path id="body" fill="#97BD40" d="M123.467,99.008c-0.3,1.287-1.587,2.086-2.873,1.786l0,0c-1.287-0.3-2.086-1.587-1.786-2.873l5.159-22.099c0.3-1.287,1.587-2.086,2.873-1.786l0,0c1.287,0.3,2.086,1.587,1.786,2.873L123.467,99.008z"/>
</g>

I want to move this element around the screen (e.g., I want to move it up and then left and then down again to the initial position), so I first create a canvas and get the element. I use this code:

var canvas = Snap("div#canvas");

Snap.load("MyImage.svg", function (image) {

    var butterfly = image.select("g#butterfly");    
    canvas3.append(butterfly);

    // Now I want to move the element around...
}

Does anybody have an idea?

I've found information about moving a circle or a rectangle, which have attributes like x, y, cx or cy that are easy to modify, but in my case I don't have those attributes...

Robert Longson

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); 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Make loaded svg invisible in snap.svg

From Dev

Creating a Snap.svg object from an <object> element

From Dev

How to get the SVG root element in Snap.svg?

From Dev

Prevent browsers moving SVG elements around page breaks

From Dev

Moving a SVG element in Firefox fails

From Dev

Snap SVG translate element that has rotation

From Dev

Moving SVG group in z space with Snap.svg

From Dev

Scale loaded SVG and zoom in with snap svg

From Dev

Snap SVG - Animating a path element

From Dev

is it possible to wrap an anchor tag around the circle element in an svg element?

From Dev

Getting arbitrary paths to animate by moving the shortest distance in Snap.svg

From Dev

Masked element in Snap SVG doesn't come into view when translated

From Dev

Moving <text> around within an svg element

From Dev

Snap.svg - Select second text element?

From Dev

How to snap svg element to grid while dragging in force layout

From Dev

Snake-Like Moving Glow around an element

From Dev

Make loaded svg invisible in snap.svg

From Dev

Moving a SVG element in Firefox fails

From Dev

Bounding snap.svg element to svg area

From Dev

Scale loaded SVG and zoom in with snap svg

From Dev

element toDefs and use with Snap.svg

From Dev

Snap SVG - Animating a path element

From Dev

is it possible to wrap an anchor tag around the circle element in an svg element?

From Dev

Is there any method to find element by snap id in Snap svg?

From Dev

Moving a canvas element around on webpage

From Dev

Snap.svg draggin Path Element

From Dev

Get attributes of use element that are defined by defs element with snap.svg

From Dev

Snap.js - how to set attribute to loaded svg

From Dev

How to convert a DOM element into a Snap.svg element?

Related Related

  1. 1

    Make loaded svg invisible in snap.svg

  2. 2

    Creating a Snap.svg object from an <object> element

  3. 3

    How to get the SVG root element in Snap.svg?

  4. 4

    Prevent browsers moving SVG elements around page breaks

  5. 5

    Moving a SVG element in Firefox fails

  6. 6

    Snap SVG translate element that has rotation

  7. 7

    Moving SVG group in z space with Snap.svg

  8. 8

    Scale loaded SVG and zoom in with snap svg

  9. 9

    Snap SVG - Animating a path element

  10. 10

    is it possible to wrap an anchor tag around the circle element in an svg element?

  11. 11

    Getting arbitrary paths to animate by moving the shortest distance in Snap.svg

  12. 12

    Masked element in Snap SVG doesn't come into view when translated

  13. 13

    Moving <text> around within an svg element

  14. 14

    Snap.svg - Select second text element?

  15. 15

    How to snap svg element to grid while dragging in force layout

  16. 16

    Snake-Like Moving Glow around an element

  17. 17

    Make loaded svg invisible in snap.svg

  18. 18

    Moving a SVG element in Firefox fails

  19. 19

    Bounding snap.svg element to svg area

  20. 20

    Scale loaded SVG and zoom in with snap svg

  21. 21

    element toDefs and use with Snap.svg

  22. 22

    Snap SVG - Animating a path element

  23. 23

    is it possible to wrap an anchor tag around the circle element in an svg element?

  24. 24

    Is there any method to find element by snap id in Snap svg?

  25. 25

    Moving a canvas element around on webpage

  26. 26

    Snap.svg draggin Path Element

  27. 27

    Get attributes of use element that are defined by defs element with snap.svg

  28. 28

    Snap.js - how to set attribute to loaded svg

  29. 29

    How to convert a DOM element into a Snap.svg element?

HotTag

Archive