After running an animation in 4 steps, I want it to restart once all the steps are completed.
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 attempted to use an if statement to reset the count back to 0 after reaching the last step.
if (i == 3)
{
i=0;
}
However, this caused the browser to crash as it entered an infinite loop. I'm seeking guidance on how to rectify this issue.