两个动画之间的jQuery延迟

码:

$("#telecomGrayscale", this).stop().animate({ top: '467px' }, { duration: 400 }).delay(800).queue(function() { $("#boxcaptionTelecom", this).stop().animate({ top: '272px' }, { duration: 900 }); }); 

上面的代码不能正常工作。 queue()内的第二个动画不起作用。

我只需要延迟第二个动画。 还试过setTimeout和setInterval无法使它们工作。

在你的第二个动画中, this不是你想象的那样,所以带有this作为上下文的选择器很可能是空的。

试试这是否有效:

 var self = this; $("#telecomGrayscale", self) .stop() .animate( { top: '467px' }, { duration: 400 } ) .delay(800) .queue( function() { $("#boxcaptionTelecom", self) .stop() .animate( { top: '272px' }, { duration: 900 } ); return $(this).dequeue(); } ); 

我认为它应该在链中:

 $("#telecomGrayscale", this).stop().animate({ top: '467px' }, { duration: 400 }).delay(800).animate({ top: '272px' }, { duration: 900 }); 

编辑:原谅我的错误。 如果你想在两个不同的元素上创建它,那么你应该创建queue()’fx’的第一个参数,然后作为第二个参数你的函数。 查看http://api.jquery.com/queue/上的function文档