.stop( [clearQueue ] [, jumpToEnd ] )Returns: jQuery
Description: Stop the currently-running animation on the matched elements.
-
version added: 1.2.stop( [clearQueue ] [, jumpToEnd ] )
-
version added: 1.7.stop( [queue ] [, clearQueue ] [, jumpToEnd ] )
-
queueType: StringThe name of the queue in which to stop animations.
-
clearQueue (default:
false
)Type: BooleanA Boolean indicating whether to remove queued animation as well. Defaults tofalse
. -
jumpToEnd (default:
false
)Type: BooleanA Boolean indicating whether to complete the current animation immediately. Defaults tofalse
.
-
.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()
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
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.
.stop()
method is evident when we need to animate an element on mouseenter
and mouseleave
:
1
2
3
4
|
|
.stop(true, true)
to the chain:
1
2
3
4
5
|
|
Toggling Animations
.stop()
will trigger jQuery's internal effects tracking. In previous versions, calling the .stop()
method before a toggled animation was completed would cause the animation to lose track of its state (if jumpToEnd was false). Any subsequent animations would start at a new "half-way" state, sometimes resulting in the element disappearing. To observe the new behavior, see the final example below.
$.fx.off
to true
. When this is done, all animation methods will immediately set elements to their final state when called, rather than displaying an effect.
Examples:
Example 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
|
Demo:
Example 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
|