Demyd Ganenko
Demyd Ganenko

Reputation: 108

Snap.svg scale and animate SVG

I'm trying to scale my SVG with g.animate({ transform: "s2.5,2.5," + bbox.cx + "," + bbox.cy }, 0); and then animate wheelAnimation(bbox.cx, bbox.cy, 1500);

var i = 0;
function wheelAnimation(cx, cy, speed){
    i++;
    g.animate(
        { transform: "r360," + cx + ',' + cy}, // Basic rotation around a point. No frills.
        speed, // Nice slow turning rays
        function(){
            if(i == 5)
                speed = 5000;
            g.attr({ transform: 'rotate(0 ' + cx + ' ' + cy}); // Reset the position of the rays.
            wheelAnimation(cx,cy, speed); // Repeat this animation so it appears infinite.
        }
    );
}

But my SVG didn't scaling. It's only rotates. If I remove rotation - SVG scaling. How to combine it to immediately scale and then animate rotation?

Plunker example

Upvotes: 1

Views: 666

Answers (1)

fl0w
fl0w

Reputation: 83

I've never used Snap.svg but you might try this:

var i = 0;

function wheelAnimation(cx, cy, speed, scale){
   i++;
   g.attr({ transform: "r0 " + cx + " " + cy + " s" + scale + "," + scale + "," + cx + "," + cy }); //Reset + Scale setup
   g.animate({ 
      transform: "r360," + cx + "," + cy + " s" + scale + "," + scale + "," + cx + "," + cy }, // Basic rotation around a point. No frills.
      speed, // Nice slow turning rays
      function(){
         if(i == 5)
            speed = 5000;
         wheelAnimation(cx, cy, speed, scale); // Repeat this animation so it appears infinite.
      }
   );
}

Hope this helps you :)

See Plunkr

Upvotes: 3

Related Questions