如何在jQuery中停止效果 [英] How do I stop an effect in jQuery

查看:107
本文介绍了如何在jQuery中停止效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面使用

$(id).show("highlight", {}, 2000);

在我启动ajax请求时突出显示一个元素,这可能会失败,所以我想要使用某些东西喜欢

to highlight an element when I start a ajax request, that might fail so that I want to use something like

$(id).show("highlight", {color: "#FF0000"}, 2000);

。问题是,如果第一个突出显示尚未完成,则第二个突出显示在队列中,并且在第一个突出显示准备好之前不会运行。因此问题:我可以以某种方式停止第一个效果吗?

in the error handler. The problem is that if the first highlight haven't finished, the second is placed in a queue and wont run until the first is ready. Hence the question: Can I somehow stop the first effect?

推荐答案

来自jQuery文档:

From the jQuery docs:

http://docs.jquery.com/Effects/stop


停止匹配元素上当前正在运行的动画。 ...

在元素上调用 .stop()时,会立即停止当前运行的动画(如果有)。例如,如果在调用 .stop()时调用 .slideUp()元素,则现在仍将显示元素,但它将是其先前高度的一小部分。不调用回调函数。

When .stop() is called on an element, the currently-running animation (if any) is immediately stopped. If, for instance, an element is being hidden with .slideUp() when .stop() is called, the element will now still be displayed, but will be a fraction of its previous height. Callback functions are not called.

如果在同一元素上调用多个动画方法,则后面的动画将放置在元素的效果队列中。这些动画直到第一个动画完成才会开始。当调用 .stop()时,队列中的下一个动画立即开始。如果 clearQueue 参数的值为 true ,则会删除队列中的其余动画,从不运行。

If more than one animation method is called on the same element, the later animations are placed in the effects queue for the element. These animations will not begin until the first one completes. When .stop() is called, the next animation in the queue begins immediately. If the clearQueue parameter is provided with a value of true, then the rest of the animations in the queue are removed and never run.

如果 jumpToEnd 参数的值为true,则当前动画停止,但是element立即被赋予每个CSS属性的目标值。在上面的 .slideUp()示例中,该元素将立即隐藏。然后立即调用回调函数,如果提供...

If the jumpToEnd argument is provided with a value of true, the current animation stops, but the element is immediately given its target values for each CSS property. In our above .slideUp() example, the element would be immediately hidden. The callback function is then immediately called, if provided...

这篇关于如何在jQuery中停止效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆