【发布时间】:2014-03-11 13:04:11
【问题描述】:
只有在另一个完成时才需要开始动画?这是我所拥有的:
$( "div.line" ).each(function() {
$( this ).animate({
height: "100%",
}, 1000 );
});
【问题讨论】:
标签: jquery animation jquery-animate each
只有在另一个完成时才需要开始动画?这是我所拥有的:
$( "div.line" ).each(function() {
$( this ).animate({
height: "100%",
}, 1000 );
});
【问题讨论】:
标签: jquery animation jquery-animate each
尝试使用.delay()
$("div.line").each(function (i) {
$(this).delay(i* 1000).animate({
height: "100%",
}, 1000);
});
【讨论】:
你可以像这样使用回调:
$('.cellcontent').animate({
height: '100%'
},
{
duration: 1000,
complete: function(){
alert('call another animate function here');
}
});
【讨论】:
除了delay(),您还可以使用setTimeout:
$( "div.line" ).each(function(i) {
setTimeout(function(){
$(this).animate({
height: "100%",
}, 1000);
},500 + ( i * 500 ));
});
【讨论】:
以下是如何正确使用回调的示例:
$(function() {
var els = $('div.line'),
elsToAnim = els.length,
animCounter = 0,
animEls = function(index) {
els.eq(index).stop().animate({
height: '100%'
}, 500, function() {
animCounter++;
if (animCounter < elsToAnim) animEls(animCounter);
});
};
animEls(animCounter);
});
【讨论】: