Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery animation() - complete firing too soon

I wrote a little animation script that fades a set of stripes from left to right. After all animations are complete a callback functions shoud run.

The script is here:

http://jsfiddle.net/9zkbu/

It works fine, but I want to do the same for a right-to-left animation:

http://jsfiddle.net/FTrhX/

As you can see the callback function is fired before animation ends :( The only thing I changed is the delay(). What am I doing wrong here? Why is "complete" running before all animations finish?

like image 224
Alex Avatar asked Jan 28 '26 16:01

Alex


1 Answers

You are almost there, you did reverse the direction, but forgot on the callback to also account for the reversal. Doing this works for me:

complete: (i == 0) ? function(){alert('done');} : null

Because you are counting the other direction if you try and check complete at cols - 1 you'll get it too early, you need to get it at 0 here. try this one: http://jsfiddle.net/FTrhX/8/

like image 77
Jeremy B. Avatar answered Jan 30 '26 04:01

Jeremy B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!