27

I have been trying to learn snap.svg and I have some doubts regarding the transform properties. My question is pretty stupid but here it is

In the following sample code, what do the the numbers mean?

     {"transform" : "t-10 0 s0 32 32"}
     {"transform" : "r180 32 32"}

I am guessing that s stands for scale, Also what is the difference between animAfter and after? I am very new to SVGs.

2 Answers 2

51

The transform format is a string that is a sequence of transforms, so you can have several after each other.

Edit: Snap doesn't make a distinction between upper/lower case these days, so this part does not make a difference (it maybe worth being aware of it though, in case you see some Raphael.js code and want to understand), the rest should still be relevant though...

T/t = Translate (t is relative, T is absolute) R/r = rotate(r is relative, R is absolute) S/s = scale(s is relative, S is absolute)

Its worth looking at the Raphael transform documentation if the Snap.svg doesn't have enough information, as there is a lot of overlap.

For transformations, some will reference a 'centre of origin' about which to rotate/scale etc, as sometimes you may want the centre of origin to be the object itself, sometimes 0,0, sometimes around a specific point.

t-10 0 s0 32 32 would translate x,y -10,0 and then scale x,y,cx,cy so scale 0 on the x, 32 on the way around cx 32.

r180 32 32 would rotate 180 degrees around point 32,32. You can normally use a comma or space to separate values.

after represents "attribute" values to set after the animation finishes. animafter represents "animation" values to set after the animation finishes.

4
  • 1
    Thanks Ian, this is the second time that you have helped me out regarding svg. :D
    – Bazinga777
    Commented Dec 1, 2013 at 6:03
  • right, it looks like the translate is absolute regardless of CaSe.
    – isapir
    Commented Jul 19, 2015 at 4:56
  • if snap doesn't make a distinction between upper and lowercase, how would you translate in absolute coordinates then?
    – Shai UI
    Commented Nov 22, 2016 at 22:09
  • It performs an absolute translate normally. Do you mean how would you do a relative transform ?
    – Ian
    Commented Nov 23, 2016 at 9:43
4

Snap seems to use the same syntax as raphael. t is translate so thats translate -10 units in x. s is scale and r is rotate.

1
  • 2
    That's because both are written by Dimitry Baranovskiy, Snap is basically a modern take on Raphael which leverages a lot of the new modern browser features.
    – James
    Commented May 23, 2014 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.