Javascript jQuery animate()元素的单个队列
默认情况下,为animate()创建的jQuery队列是按元素完成的,我想知道是否有办法为使用animate()完成的所有动画创建一个队列?也就是说,一次只能发生一个动画您可以在一个元素上使用自己的自定义队列,使用队列: 大概是这样的:Javascript jQuery animate()元素的单个队列,javascript,jquery,Javascript,Jquery,默认情况下,为animate()创建的jQuery队列是按元素完成的,我想知道是否有办法为使用animate()完成的所有动画创建一个队列?也就是说,一次只能发生一个动画您可以在一个元素上使用自己的自定义队列,使用队列: 大概是这样的: $(someElement) // could also be a plain object, e.g. $({}) .queue('customQueue', function (next) { first.animate({ ...
$(someElement) // could also be a plain object, e.g. $({})
.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');
.animate()
有一个队列
选项,每个元素只允许一种效果:
队列:一个布尔值,指示是否将动画放置在效果队列中。如果为false,动画将立即开始
用法
这难道不是要一起删除队列,而不是为所有元素创建一个单独的队列吗?最接近于我试图实现的目标。在这种情况下,您可以删除
队列:false
(此答案的修订版2)@Jeffery,这取决于。如果你想让其他动画在这个队列之外进行,那么你需要队列:false
“一次只能发生一个动画”-听起来好像没有其他动画发生在我身上。很好,我仍然更喜欢这种方式作为一种通用解决方案,因为队列的行为独立于其他队列。
$(someElement) // could also be a plain object, e.g. $({})
.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');
$('div').animate({ height: 50, queue: false });