jquery wait for multiple complete events

后端 未结 5 1629
无人及你
无人及你 2020-12-16 01:23

I want to use jQuery\'s load function to load some content into a div, and I want to also call jQuery\'s animate function.

$(\'#div         


        
5条回答
  •  遥遥无期
    2020-12-16 01:52

    You'll have to keep count of how many of your events have completed, and then use that as a test in your callback:

    var complete = 0;
    
    $('#div1').load('...', function() {
        complete++;
        callback();
    });
    $('html,body').animate({
        ...: ...}, ..., '...', function(){
        complete++;
        callback();
    });
    
    function callback(){
        if ( complete < 2 ) return;
        // both are complete
    }
    

提交回复
热议问题