Snap.svg缩放和动画SVG

时间:2016-04-29 07:55:02

标签: javascript css animation svg snap.svg

我正在尝试使用g.animate({ transform: "s2.5,2.5," + bbox.cx + "," + bbox.cy }, 0);扩展我的SVG,然后设置动画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.
        }
    );
}

但我的SVG没有扩展。它只是旋转。如果我删除旋转 - SVG缩放。如何将它组合成立即缩放然后旋转动画?

Plunker example

1 个答案:

答案 0 :(得分:3)

我从未使用过Snap.svg,但你可以试试这个:

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

希望这可以帮到你:)

See Plunkr