var delay = 0;
var interval = 1000;
var reload = function() {
setTimeout(function(){
$('.bl').each(function(i){
$(this).delay(delay).animate({
height: '150px'
},500);
delay += interval;
});
},interval);
setInterval(reload,delay);
嗨伙计们,在所有人出现后都无法隐藏。
答案 0 :(得分:1)
这是一个不使用定时器的示例,只是从每个元素的动画队列返回的动画承诺:
var interval = 1000;
var reload = function () {
var delay = 0;
var promise; // "Undefined" equates to an initial resolved promise
$('.bl').css({
height: 0
}).each(function (i) {
// chain promises in parallel using repeated $.when calls
promise = $.when(promise, $(this).delay(delay).animate({
height: '150px'
}).promise());
delay += interval;
});
// When all animation promises complete, start the process pseudo-recursively
promise.then(reload);
}
reload();
JSFiddle: http://jsfiddle.net/TrueBlueAussie/rtuLzc6t/
唯一的鬼鬼祟祟是我使用promise = $.when(promise, newpromise)
并行承诺。循环的最终结果是在所有动画结束时完成的单个promise。最终then
使其递归。