Open In App

jQuery | Stop Animations

Improve
Improve
Like Article
Like
Save
Share
Report

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.




<!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>


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.




<!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>


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:



Last Updated : 27 Feb, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads