I made this quick / easy jQuery plugin for you to do what you want. :-)
$.fn.extend({ serial_fade: function(o) { if(!o.speed || o.speed == undefined || o.speed == null) { o.speed = 'slow'; } if(!o.fade || o.fade == undefined || o.fade == null) { o.fade = 'in'; } if(!o.index || o.index == undefined || o.index == null) { o.index = 0; } var s = this.selector; if(o.fade.toLowerCase() == 'in') { return this.eq(o.index).fadeIn(o.speed, function() { o.index++; if($(s).eq(o.index).length > 0) { $(s).serial_fade({speed:o.speed,fade:o.fade,index:o.index}); } }); } else { return this.eq(o.index).fadeOut(o.speed, function() { o.index++; if($(s).eq(o.index).length > 0) { $(s).serial_fade({speed:o.speed,fade:o.fade,index:o.index}); } }); } } }); // To call it just do this: $(ele).serial_fade({speed:'slow',fade:'in'}); // Optionally, you can pass which element you want to start with (0-based): $('a').serial_fade({speed:'slow',fade:'in',index:2}); // If you want to start with element 2 (3, really) and fade all the rest *out* // sequentially, verrry slowly: $(ele).serial_fade({speed:5000,fade:'out',index:2});
It should work with any kind of selector, like any other jQuery method. Hope this works for you.
Edit: I expanded it so that it could fade and fade. It just seems more useful so ...
source share