I have an animation running in 4 steps, when the 4 steps are over, I would like it to restart.
var aSteps = [
{
"x": "800",
"y": "0"
},
{
"x": "800",
"y": "500"
},
{
"x": "0",
"y": "500"
}, {
"x": "0",
"y": "0"
}
];
var iStepsLength = aSteps.length;
for (var i = 0; i < iStepsLength; i++)
{
$('#P1').animate
({
left: aSteps[i].x,
top: aSteps[i].y,
}, 1000);
}
I've tried to add an if statement like.
if (i == 3)
{
i=0;
}
But then my browser will just crash because it runs the for loop infinitely. I hope that you can help me out, and teach me what it is that I'm doing wrong.
window.setTimeout