jQuery | Stop Animations

The jQuery stop() method in jQuery is used to stop animations or effects before it is finished.
This method works on all type of animation like sliding, fading, and custom animations.

Syntax:

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

Example-1: Stop sliding animation.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>jQuery stop() Method
  </title>
    <script src=
  </script>
    <style>
        #panel,
        #flip {
            padding: 5px;
            font-size: 18px;
            text-align: center;
            background-color: green;
            color: white;
            border: solid 1px #666;
            border-radius: 3px;
        }
          
        #panel {
            padding: 50px;
            display: none;
        }
    </style>
</head>
  
<body>
    <center>
        <h1 style="color:green;">  
            GeeksForGeeks</h1>
        <h2 id="GFG">
          jQuery stop() Method</h2>
        <br>
        <button id="stop">Click
      </button>
        <br>
        <br>
        <div id="flip">
            <h2>GeeksForGeeks</h2></div>
        <div id="panel">
          A computer science portal for geeks
      </div>
        <script>
            $(document).ready(function() {
                $("#flip").click(function() {
                    $("#panel").slideDown(5000);
                });
                $("#stop").click(function() {
                    $("#panel").stop();
                });
            });
        </script>
    </center>
</body>
  
</html>

chevron_right


Output:

Before clicking on the GeeksForGeeks:

After clicking on the GeeksForGeeks and not clicking on Button:

After clicking on the GeeksForGeeks and click on Button:

Example-2: Stop sliding from left to right.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>jQuery stop() Method</title>
    
    <script src=
  </script>
    
    <style>
        #panel,
        #flip {
            padding: 5px;
            font-size: 18px;
            text-align: center;
            background-color: green;
            color: white;
            border: solid 1px #666;
            border-radius: 3px;
        }
          
        #panel {
            padding: 50px;
            display: none;
        }
    </style>
</head>
  
<body>
    <center>
        <h1 style="color:green;">  
            GeeksForGeeks</h1>
        <h2 id="GFG"> jQuery stop() Method</h2>
        <br>
        <button id="start">Start</button>
        <button id="stop">Stop</button>
        <br>
        <br>
        <div style="background:green;
                    height:100px;
                    width:400px;
                    position:absolute;">
          GeeksForGeeks
      </div>
        <script>
            $(document).ready(function() {
                $("#start").click(function() {
                    $("div").animate({
                        left: '80px'
                    }, 5000);
                    $("div").animate({
                        fontSize: '3em'
                    }, 5000);
                });
  
                $("#stop").click(function() {
                    $("div").stop();
                });
            });
        </script>
    </center>
</body>
  
</html>

chevron_right


Output:

Before clicking on the Start:

After clicking on the Start and not clicking on Stop:

After clicking on the Start and clicking on Stop:



My Personal Notes arrow_drop_up

Small things always make you to think big

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.