← Back to Chapters

jQuery stop() Tutorial

⏹️ jQuery stop() Tutorial

? Quick Overview

The stop() method in jQuery is used to immediately stop the currently running animations on selected elements.

? Key Concepts

  • Stops active jQuery animations
  • Prevents animation queue buildup
  • Can optionally clear queue and jump to end state

? Syntax & Theory

The stop() method can take two optional boolean parameters to control animation behavior.

? View Code Example
// Basic syntax of jQuery stop()
$(selector).stop(clearQueue, jumpToEnd);

? Code Example – Start & Stop Animation

Animate and Stop me!
? View Code Example
// Start a slow animation
$("#stopBox").animate({left:"300px"},5000);
// Stop the current animation immediately
$("#stopBox").stop();

⏹️ Using stop() with Parameters

You can control animation queue clearing and whether the element jumps to the final state.

? View Code Example
// Stop animation and clear queued animations
$("#stopBox").stop(true);
// Stop animation, clear queue, and jump to end position
$("#stopBox").stop(true,true);

? Live Output Explanation

Clicking stop buttons immediately halts the animation. Using parameters gives precise control over animation state and queue behavior.

? Interactive Playground

Start the Chained Sequence to see 3 animations in a row (Move Right → Expand → Fade Out). Try the different stop buttons while the box is moving!

Playground

? Use Cases

  • Hover-based animations
  • Preventing animation stacking
  • Interactive UI controls
  • Game or dashboard animations

✅ Tips & Best Practices

  • Use stop(true) for rapid UI interactions
  • Combine with hover() to avoid jittery animations
  • Keep animation durations reasonable

? Try It Yourself

  • Create a hover animation using mouseenter and mouseleave
  • Test stop() with multiple chained animations
  • Observe differences between default and parameterized stop