Snap SVG translate element that has rotation

Trevor Orr

I am trying to move (translate) an object that has been rotated, when I move (translate) the rotated object it loses it's rotation and does move correctly. If the use the same code on an object that is not rotated then the move correctly. What I am doing wrong here?

Here is a fiddle

This code loses the rotation.

var part = s.select("#part_2");
var t = new Snap.Matrix();
t.translate(part.getBBox().x,part.getBBox().y+18);
part.transform(t);
Robert Longson

I'm not sure what order you want the transforms to apply. If you want the squares to move such that down is applied after transforming i.e. down for the rotated matrix is at an angle you'd do this...

    var t = part.transform().localMatrix;
    t.translate(0, 18);
    part.transform(t);

If, however you want down to always be down then you'd do something like this...

    var t = new Snap.Matrix();
    t.translate(0, 18);
    t.add(part.transform().localMatrix);
    part.transform(t);

The trick is to get the existing matrix for the shape and append/prepend the transform you want to it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Basic rotation using Snap.svg

From Dev

snap.svg: wrong origin point of rotation

From Dev

SVG image element rotation

From Dev

Snap SVG - Animating a path element

From Dev

Snap SVG - Animating a path element

From Dev

Bounding snap.svg element to svg area

From Dev

Snap.svg Getting rotation from slope in point difference

From Dev

Get current rotation in degrees of group in snap.svg

From Dev

Snap.svg Getting rotation from slope in point difference

From Dev

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

From Dev

Snap.svg - Select second text element?

From Dev

Snap SVG - Moving a loaded element around

From Dev

element toDefs and use with Snap.svg

From Dev

Snap.svg draggin Path Element

From Dev

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

From Dev

How to set a rotation point on a nested SVG Element

From Dev

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

From Dev

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

From Dev

How do you get the rotation value of an svg object with snap.svg?

From Dev

Snap.svg return object says "Object has no circle method"

From Dev

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

From Dev

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

From Dev

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

From Dev

Snap.svg error when passing a Snap.animation to Element.animate

From Dev

Translate (gradually - with animate) an svg element after a delay using jQuery

From Dev

How do I update an SVG text element using Snap.svg?

From Dev

Snap.svg can't find dynamically (and successfully) appended SVG element with jQuery

From Dev

Snap.svg - Stop hover event retriggering on a sub-element of the hoverable Element

From Dev

Snap.svg animate

Related Related

  1. 1

    Basic rotation using Snap.svg

  2. 2

    snap.svg: wrong origin point of rotation

  3. 3

    SVG image element rotation

  4. 4

    Snap SVG - Animating a path element

  5. 5

    Snap SVG - Animating a path element

  6. 6

    Bounding snap.svg element to svg area

  7. 7

    Snap.svg Getting rotation from slope in point difference

  8. 8

    Get current rotation in degrees of group in snap.svg

  9. 9

    Snap.svg Getting rotation from slope in point difference

  10. 10

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

  11. 11

    Snap.svg - Select second text element?

  12. 12

    Snap SVG - Moving a loaded element around

  13. 13

    element toDefs and use with Snap.svg

  14. 14

    Snap.svg draggin Path Element

  15. 15

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

  16. 16

    How to set a rotation point on a nested SVG Element

  17. 17

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

  18. 18

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

  19. 19

    How do you get the rotation value of an svg object with snap.svg?

  20. 20

    Snap.svg return object says "Object has no circle method"

  21. 21

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

  22. 22

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

  23. 23

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

  24. 24

    Snap.svg error when passing a Snap.animation to Element.animate

  25. 25

    Translate (gradually - with animate) an svg element after a delay using jQuery

  26. 26

    How do I update an SVG text element using Snap.svg?

  27. 27

    Snap.svg can't find dynamically (and successfully) appended SVG element with jQuery

  28. 28

    Snap.svg - Stop hover event retriggering on a sub-element of the hoverable Element

  29. 29

    Snap.svg animate

HotTag

Archive