开发者

JQuery each function how to force consecutive operation

Using JQuery .each function() yet it is operating on all elements at the same time. Instead I want it to be sequential. So operating开发者_运维问答 on one function once complete the second etc.. etc..

  $('#fader').children().hide();

$('#fader').children().each(function(){

        $(this).fadeIn(2000,function(){
            $(this).delay(4000);
            $(this).fadeOut(2000);
        });     
    });


You can do it with a recursive function like this:

function fader(elm) {
  elm.fadeIn(2000, function(){
    elm.delay(4000);
    elm.fadeOut(2000, function() {
      if (elm.next()) {
        fader(elm.next());
      }
    });
  });
}

$('#fader').children().hide();

fader($('#fader').children(':first'));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜