What is the difference between using a stop()
with the clearQueue
parameter set to true and just using the clearqueue()
, and if there is no difference why both?
使用将clearQueue参数设置为true的stop()和使用clearQueue()的区别是什么?如果没有区别,为什么两者都有呢?
2 个解决方案
#1
7
From the api docs, .stop()
is meant only for animation, however .clearqueue()
will remove any function attached to a standard jquery queue.
从api文档中,.stop()仅用于动画,但是.clearqueue()将删除任何附加到标准jquery队列的函数。
From the docs:
从文档:
When the .clearQueue() method is called, all functions on the queue that have not been executed are removed from the queue. When used without an argument, .clearQueue() removes the remaining functions from fx, the standard effects queue. In this way it is similar to .stop(true). However, while the .stop() method is meant to be used only with animations, .clearQueue() can also be used to remove any function that has been added to a generic jQuery queue with the .queue() method.
当调用. clearqueue()方法时,未执行的队列上的所有函数将从队列中删除。如果不使用参数,. clearqueue()将从标准效果队列fx中删除其余的函数。在这种情况下,它类似于。stop(true)。但是,虽然.stop()方法只用于动画,但是. clearqueue()也可以用于删除任何添加到普通jQuery队列中的函数,使用.queue()方法。
#2
1
jQuery supports a number of queues, the most common of which is the fx
queue for animations. .stop()
works only on the fx
queue, while clearQueue
lets you specify some other (custom) queue.
jQuery支持许多队列,其中最常见的是用于动画的fx队列。
Here is an example with a custom queue:
下面是一个自定义队列的示例:
// First function to queue
function a1(next) {
setTimeout(function () {
alert("one");
next();
}, 1000);
}
// Second function to queue
function a2(next) {
setTimeout(function () {
alert("two");
next();
}, 1000);
}
// Queue both functions and start it off
$('body').queue('alerts', a1).queue('alerts', a2).dequeue('alerts');
// Clear the queue to prevent the second alert from showing
$('body').clearQueue('alerts');
See the demo.
看演示。
#1
7
From the api docs, .stop()
is meant only for animation, however .clearqueue()
will remove any function attached to a standard jquery queue.
从api文档中,.stop()仅用于动画,但是.clearqueue()将删除任何附加到标准jquery队列的函数。
From the docs:
从文档:
When the .clearQueue() method is called, all functions on the queue that have not been executed are removed from the queue. When used without an argument, .clearQueue() removes the remaining functions from fx, the standard effects queue. In this way it is similar to .stop(true). However, while the .stop() method is meant to be used only with animations, .clearQueue() can also be used to remove any function that has been added to a generic jQuery queue with the .queue() method.
当调用. clearqueue()方法时,未执行的队列上的所有函数将从队列中删除。如果不使用参数,. clearqueue()将从标准效果队列fx中删除其余的函数。在这种情况下,它类似于。stop(true)。但是,虽然.stop()方法只用于动画,但是. clearqueue()也可以用于删除任何添加到普通jQuery队列中的函数,使用.queue()方法。
#2
1
jQuery supports a number of queues, the most common of which is the fx
queue for animations. .stop()
works only on the fx
queue, while clearQueue
lets you specify some other (custom) queue.
jQuery支持许多队列,其中最常见的是用于动画的fx队列。
Here is an example with a custom queue:
下面是一个自定义队列的示例:
// First function to queue
function a1(next) {
setTimeout(function () {
alert("one");
next();
}, 1000);
}
// Second function to queue
function a2(next) {
setTimeout(function () {
alert("two");
next();
}, 1000);
}
// Queue both functions and start it off
$('body').queue('alerts', a1).queue('alerts', a2).dequeue('alerts');
// Clear the queue to prevent the second alert from showing
$('body').clearQueue('alerts');
See the demo.
看演示。