I’d like to be able to create an animation that can be played and stopped (reset).
Here is what I have so far:
function animateObject(amountArray) {
// Sample data
amountArray = ["0", "1", "3", "2", "0"];
duration = 500;
// Looping through each value and animating the object
for(i=0; i<amountArray.length; i++) {
$('#object').animate({
top: amountArray[i]
},duration);
} // endloop
}
This accurately animates the object but calling $('#object').stop(); anywhere doesn’t seem to stop the animation.
I presume that is because the loop is already built out and nothing can stop it after it’s executed.
Try calling
.stop(true). That should clear queued animations.