Jquery - defer callback until multiple animations are complete

后端 未结 6 450
情书的邮戳
情书的邮戳 2020-12-09 03:03

I need a callback to execute once after multiple elements have finished animating. My jquery selector is as follows:

$(\'.buttons\').fadeIn(\'fast\',function         


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 03:30

    var $buttons = $('.buttons');
    
    $buttons.each( function (index) { 
        if ( index == $buttons.length - 1 ) {
            $(this).fadeIn('fast',function() {
               // my callback
            });
        } else {
            $(this).fadeIn('fast');
        }
    });
    

    Untested but this should apply the callback to the last button only.

提交回复
热议问题