Skip to main content

Archive

Show more

jQuery Stop

jQuery - Stop

Stop is a method in jQuery used to stop animations on selected elements. It is useful for interrupting and clearing queued animations.


1. Basic Usage

The stop() method in jQuery is used to stop animations on selected elements.

Example:

// Stop all animations on an element
$("#myElement").stop();

// Stop a specific animation (e.g., fade) on an element
$("#myElement").stop("fade");

In this example, the stop() method is used to stop all animations or a specific animation (e.g., fade) on the element with the ID myElement.


2. Clearing the Animation Queue

The stop() method with the true parameter can be used to clear the animation queue of selected elements.

Example:

// Clear the animation queue and stop the current animation
$("#myElement").stop(true);

In this example, the animation queue of the element is cleared, and the current animation is stopped.


3. Jump to End of Animation

The stop() method with the true and true parameters can be used to jump to the end of the current animation on selected elements.

Example:

// Jump to the end of the current animation and clear the queue
$("#myElement").stop(true, true);

In this example, the animation queue is cleared, and the current animation is stopped, jumping to its end.


4. Conclusion

Stop is a versatile method in jQuery for managing animations on selected elements. By stopping animations, clearing animation queues, and jumping to the end of animations, developers can precisely control the animation behavior in their web applications.

Comments