如何停止功能运行? [英] How to stop a function from running?
问题描述
我有一个函数,但是即使我调用stop()
,它也可以继续运行.
函数名称为function slide() { //codes here }
I have a function but it keeps on running even if I call a stop()
.
The function name is function slide() { //codes here }
slide().stop();
如何阻止它运行?
以及如何在停止后再次运行它?
因此,我将完全控制它.
How to stop it from running?
And how to run it again after stopping it?
So I will be having a full control on it.
推荐答案
.stop
是一种用于停止在当前元素上异步运行(在后台)的动画的方法.它不会中断/停止任何未使用效果库的代码.
.stop
is a method for stopping animations that is running asynchronously (in the background) on the current element. It doesn't interrupt/stop any other code that isn't using the effects library.
相反,您应该看看 .queue
,它可以让您设置自定义队列您可以清除或出队.
Instead you should take a look at .queue
which lets you setup custom queues that you can clear or dequeue.
关于如何使用.queue
已经存在很好的答案,所以我将带您到该问题:
There already exist very good answers on how to use .queue
so I'll point you to that question instead: Can somebody explain jQuery queue to me? - Look at the answer by gnarf.
这篇关于如何停止功能运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!