jQuery stop() Method – Halting Animations and Effects
The stop() method in jQuery is used to immediately halt ongoing animations or effects before they complete. This method works with all animation types, including sliding, fading, and custom animate() actions.
Syntax:
$(selector).stop(stopAll, goToEnd);
- stopAll (optional) – A boolean that determines whether the animation queue should be cleared.
- false (default): Only the current animation stops; queued animations will still run.
- true: Stops the current animation and clears all queued ones.
2.goToEnd (optional) – A boolean that decides if the animation should jump to its final state.
- false (default): Animation stops at its current point.
- true: Animation immediately finishes and applies final styles.
Example – Basic Usage:
Here’s how to stop a sliding animation when a "Stop" button is clicked:
$("#stop").click(function() {
$("#panel").stop();
});
This stops any active animation on #panel as soon as the button with #stop is clicked.