I am using Snap.svg and I have the following code:
http://jsfiddle.net/vdfu010q/8/
Which creates 7 black rectangles. I have a function (rectAnim
) which animates the rectangles. I need them to animate in different timings, so I created that setInterval
method to delay their animation, but it is not working.
If you remove it and leave only the function call, you'll see the animation running, but the setInterval
seems to break it all.
What am I doing wrong? How can I make each rectangle animate with different timings?
var s = Snap('#stuff');
function rectAnim(tgt){
tgt.animate({
width: 100,
x: 50
}, 1000, mina.easeinout, function(){
tgt.animate({
width: 200,
x: 0
}, 1000, mina.easeinout, function(){
tgt.animate({
width: 100,
x: 50
}, 1000, mina.easeinout, rectAnim(tgt));
});
});
}
for(var i = 0; i < 7; i++){
var obj = s.rect(0, 41 * i, 200, 40);
obj.node.setAttribute('id', 'strap' + i);
setInterval(function(){
rectAnim(obj);
}, 200 * i);
}