我想使用 jQuery 的 load
函数将一些内容加载到一个 div 中,我还想调用 jQuery 的 animate
函数。
$('#div1').load('...', function() {
// load complete
});
$('html,body').animate({
...: ...}, ..., '...', function(){
// animate complete
});
我不想在调用 animate
之前等待 load
完成,反之亦然。
在此之后,我想调用第三个函数,但我不想调用它,直到 load
和 animate
的 complete 事件都被触发.
我该怎么做?
最佳答案
听起来像是 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!
});
关于javascript - jquery 等待多个完成事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7432815/