我正在尝试使每个语句中的 div 淡入/淡出。问题是在淡入/淡出完成之前调用下一个项目。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"></script>
<div id='one'>one</div>
<div id='two'>two</div>
<div id='three'>three</div>
<script>
$.each([ "one", "two", "three"], function() {
console.log( 'start - ' + this );
animate( this );
console.log( 'end - ' + this );
});
function animate( id )
{
box = '#' + id;
$(box).fadeOut( 500, function( )
{
console.log('showing - ' + id);
$(box).fadeIn( 500 );
$(box).css('backgroundColor','white');
});
}
</script>
控制台显示 -
start - one
end - one
start - two
end - two
start - three
end - three
showing - one
showing - two
showing - three
我想要类似的东西 -
start - one
showing - one
end - one
start - two
showing - two
end - two
start - three
showing - three
end - three
那么在继续下一个值之前,我如何才能等待每个“每个”都完全完成呢?