jquery wait for multiple complete events

后端 未结 5 1634
无人及你
无人及你 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条回答
  •  旧时难觅i
    2020-12-16 01:56

    Sounds like a job for Deferred: http://api.jquery.com/category/deferred-object/

    var load = $.Deferred(function (dfd) {
      $('#div1').load(…, dfd.resolve);
    }).promise();
    
    var animate = $('html,body').animate(…);
    
    $.when(load, animate).then(function () {
      // Do your thing here!
    });
    

提交回复
热议问题