各ステートメント内にある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
では、次の値に進む前に、各「各」が完全に終了するのをどのように待つことができますか?