问题
I am using Raphael JS library and here is my code:
var rectangle = paper.rect(0, 0, 5, 5);
rectangle.attr({opacity: 0});
// I need here a 5 seconds delay, before starting an animation
rectangle.animate({opacity: 1}, 2000);
I have tried rectangle.attr({opacity: 0}).delay(5000);
and also this: rectangle.attr({opacity: 0}, 5000);
, but none of these seems to work at all.
What is the simplest way to wait some time before excuting other code. I would not like to use nested functions or for loops at all, if possible.
回答1:
Use Raphael.animation and Animation.delay.
var anim = Raphael.animation({opacity: 0, opacity: 1}, 1000);
rectangle.animate(anim.delay(5000 /* the delay (ms) */));
来源:https://stackoverflow.com/questions/11626589/delay-between-opacity-0-and-starting-animation-to-opacity-1-in-raphael-js