jquery callbacks being called multiple times

后端 未结 3 900
借酒劲吻你
借酒劲吻你 2020-12-15 06:47

When I use the fade/slide/animate functions in jQuery the callback gets called multiple times for each element the effect is applied to. This is by design of course. I jus

3条回答
  •  爱一瞬间的悲伤
    2020-12-15 07:16

    That would produce the alert when the fadeOut on the last element was called. That would not necessarily be the last fadeOut.

    var numDivs = $('div').length;
    $('div').fadeOut(1000, function() {
      if( --numDivs > 0 ) return;
      alert('this is the final fadeout to complete');
    });
    

    Check it out on JSFiddle

提交回复
热议问题