jQuery animate()元素的单个队列
默认情况下,为animate()创建的jQuery队列是按元素完成的,我想知道是否有办法为animate()完成的所有动画创建单个队列? 即,一次只能发生一个动画
您可以使用队列在一个元素上使用自己的自定义队列来执行此操作:
$(function(){ $('#myQueue') .queue('myQueue',function(next){ $('#t1').animate({left: 100}, {duration: 1000, queue: false, complete: next }) }) .queue('myQueue',function(next){ $('#t2').animate({left: 100}, {duration:1000, queue:false, complete: next}) }) /* etc. */ .dequeue('myQueue') })
.animate()
有一个queue
选项,每个元素只允许一个效果:
queue:一个布尔值,指示是否将动画放在效果队列中。 如果为false,则动画将立即开始。
用法
$('div').animate({ height: 50, queue: false });
像这样的东西:
$(someElement) // could also be a plain object, eg $({}) .queue('customQueue', function (next) { first.animate({ ... }, function () { // when the animation is complete, call next() for customQueue next(); }); }) .queue('customQueue', function (next) { second.animate({ ... }, function () { // when the animation is complete, call next() for customQueue next(); }); }) // add more animations, then .dequeue('customQueue');