小编sco*_*ott的帖子

等待每个jQuery

我试图让每个声明中的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>
Run Code Online (Sandbox Code Playgroud)

控制台节目 -

start - one
end - one
start - two
end - two
start - three
end …
Run Code Online (Sandbox Code Playgroud)

each jquery wait

8
推荐指数
1
解决办法
3551
查看次数

标签 统计

each ×1

jquery ×1

wait ×1