Advertisement

Google Ad Slot: content-top

jQuery Stop


The jQuery stop() method is used to stop animations or effects before it is finished.


jQuery .stop() Method



The .stop() method is used to halt ongoing animations or effects immediately before they finish. It applies to:


  • Sliding effects.slideDown(), .slideUp(), .slideToggle()
  • Fading effects .fadeIn(), .fadeOut(), .fadeToggle(), .fadeTo()
  • Custom animations.animate({})


Syntax:


$(selector).stop(stopAll, goToEnd);


Parameters:

  • stopAll (optional):

true clears the animation queue.

false (default) keeps queued animations.

  • goToEnd (optional):

true jumps to the final state of the current animation.

false (default) leaves it where it is.


So, by default, the stop() method kills the current animation being performed on the selected element.


The following example demonstrates the stop() method, with no parameters:

Example
<script>
$(document).ready(function(){
$("#startBtn").click(function(){
$("#box").animate({width: "400px"}, 3000);
});

$("#stopBtn").click(function(){
$("#box").stop();
});
});
</script>
Try it yourself