Suppose you had a long animation where you were changing the width:
var myTargetWidth = 500;
$(el).animate( { "width" : myTargetWidth }, 5000 );
The animation is asynchronous so your code continues . . .
a couple seconds later you decide to change the target width to 300 . . .
the animation is still running at this point . . .
How would I change targetWidth to a different value on the running animation?
One option is to use the
stepfunction mentioned in the jQueryanimatefunction (API)to check a condition while the animation is running.
Example JSFiddle : http://jsfiddle.net/GweLA/13/
JS
CSS
HTML
Solution 2:
After some research I found that we can modify the
startandendproperties offxparameter passed to the step function to control the animation. This kind of smoothens the animation, but not a very tidy way of doing it though.Example JSFiddle : http://jsfiddle.net/GweLA/57/
JS