Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery synchronous operation

Tags:

jquery

I am fading elements one by one but it seems it all fades at once.

How can I fade elements one by one. Only if one fades completely, should the second start fading.

I loop and fade it like this

$(ele).fadeIn('slow');
like image 385
Hitz Avatar asked May 13 '26 14:05

Hitz


1 Answers

fadeIn has a callback that executes when fading is completed. Add to every element the class elemX, where x is the order of fading. Then use the following code:

startFading(1);

function startFading(order) {
   $(".ele" + order).fadeIn('slow', function() {
        if (order < orderMax) {
            startFading(order+1);
        }
   });
}
like image 109
kgiannakakis Avatar answered May 16 '26 05:05

kgiannakakis



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!