Snap.svg缩放和动画SVG(Snap.svg scale and animate SVG)

编程入门 行业动态 更新时间:2024-10-21 11:58:21
Snap.svg缩放和动画SVG(Snap.svg scale and animate SVG)

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

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

最满意答案

我从未使用过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. } ); }

希望这可以帮到你:)

见Plunkr

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

更多推荐

本文发布于:2023-07-31 00:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340524.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缩放   动画   svg   Snap   scale

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!