Suppose you have an animation running with a certain time like this:
$('span').animate({opacity : 1}, 10000);
The animation is quite long so the user tries clicking the button again. The animation will be a certain amount of time through the animation already, which is probably going to be different every time.
On the second click is it possible to update the animation process keeping the opacity of the object when the user clicks, just changing the time it will take to finish?
Basically I want to update the animation process mid way through the animation.
You can use the
stepoption ofanimateto keep track of how far along the animation is. Then with that information, you can calculate the time remaining in the animation. Then stop the current animation and start a new one with half the duration.http://jsfiddle.net/MdD45/
EDIT
It looks like the 2nd parameter passed to
stepcontains a property namedposwhich tells you what percentage along in the animation you are. That can simplify things further.http://jsfiddle.net/MdD45/1/