Jquery: Fade multiple elements one after the other

假装没事ソ 提交于 2019-12-03 20:27:03

You could do a recursive function that stops when there's no LI left like this:

function fadeLI(elem) { 
  elem.fadeIn(500, function() { fadeLI($(this).next()); }); 
}                            
fadeLI($("#list li:first")​);​

Check it out here

You want a recursive function to check if there is another li element, and fade it in if so...

function fadeInNext(el){
  if(el.next('li')){
    el.next('li').fadeIn(500,fadeInNext)
  }
}
$('...').fadeIn( 500, fadeInNext )

you can do this.. add each child into a array and make a function which see's if the length of the array is greater then 0, then it get's the first item of the Array and fadeToggle's the child which in turn toggle's a function within the fadeToggle and it jumps to the next child element.. for more information about shift() check out http://www.w3schools.com/jsref/jsref_shift.asp

var toggleList = [];
$("#container").children().each(function() {
toggleList.push(this);
});

function fadeToggleList(toggleList) {
if (toggleList.length > 0) {
    var currentChild = toggleList.shift();
    $(currentChild).fadeToggle(50, function() {
        fadeToggleList(toggleList);
    });
}
}
fadeToggleList(toggleList);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!