简体   繁体   English

捕捉SVG动画循环

[英]Snap SVG animation loop

I'm trying to figure out, how to make the entire animation loops with snap SVG. 我正在尝试弄清楚如何使用快照SVG制作整个动画循环。 I have 2 step animation with rectangles. 我有矩形的两步动画。 For now I have ended up with something like this. 现在,我最终得到了这样的结果。 Something funny is happening here. 这里发生了有趣的事情。 Firstly, the animation goes back instead of restarting, and it stops. 首先,动画返回而不是重新开始,然后停止。

function firstStep() {
   setTimeout(function () {
     bigRectangle.animate({width:250}, 3000);
     mainFooter.animate({width:250}, 3000);
     leftSidebar.animate({width:40, fill:"#22313F"}, 3000);
     rightSidebar.animate({x:460, width:40, fill:"#22313F"}, 3000);
     mainContent.animate({x:300, width:150}, 3000);
   }, 2000);
   secondStep();
}

function secondStep() {
   setTimeout(function () {
   bigRectangle.animate({width:180}, 2500);
   mainFooter.animate({width:180, y:640}, 2500);
   leftSidebar.animate({width:180, height:50}, 2500);
   rightSidebar.animate({ width:180, height:50, y:580, x:250}, 2500);
   mainContent.animate({x:250, y:170, width:180}, 2500);
   }, 6000);
}

function loopRect(){
   setInterval(firstStep, 8000);
}

loopRect();

I can see two problems: 我可以看到两个问题:

setInterval(firstStep, 3000);

This interval doesn't leave enough time for the animation to finish before it starts again. 此间隔没有足够的时间让动画在再次开始之前完成。

Also, if you want the animation to restart, you'll have to put everything back where it was. 另外,如果要重新启动动画,则必须将所有内容放回原处。 This will require a third step to your animation: 这将需要动画的第三步:

setTimeout(function () {
bigRectangle.animate({width: 400}, 2500);
mainFooter.animate({width: 400,y: 520}, 2500);
leftSidebar.animate({width: 70,height: 400,fill: "#19B5FE"}, 2500);
rightSidebar.animate({width: 70,height: 400,y: 110,x: 580,fill: "#19B5FE"}, 2500);
mainContent.animate({x: 330,y: 110,width: 240}, 2500);
}, 10000);

Actually, there is no reason why you can't put all the animation code in a single function. 实际上,没有理由不能将所有动画代码都放在一个函数中。 Here's an updated jsfiddle. 这是更新的jsfiddle。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM