Sometimes we wish to stop current running animation before it get finished. For this, in jQuery .stop() function is used to stop the running animation. This function works perfectly with various effects, fading, animations and sliding.

Syntax for Stop() jQuery

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

In the above one, stopAll parameter’s default value is false. And also it is an optional one, where the value is boolen. It is used to specify whether or not to stop the queued animations. Likewise, goToEnd is an optional parameter, which is used to mention whether or not to complete all animations immediately.

Example for Stop() without Parameter

Here, we can see one example for this stop() function to know how it works to stop animation. In this example, it doesn’t contains any parameter.

        <title>The stop Method</title> 
        <script src= 
        <!-- jQurey code to show the working of this method -->
            $(document).ready(function() { 
                $("#gfg_start").click(function() { 
                        height: 300 
                    }, 1000); 
                        width: 300 
                    }, 1000); 
                $("#gfg_stop").click(function() { 
            div { 
                background: green; 
                height: 60px; 
                width: 60px; 
            button { 
        <!-- click on this button and animation will start -->
        <button id="gfg_start">Start</button> 
        <!-- click on this button and animation will stop -->
        <button id="gfg_stop">Stop</button> 

Leave a Reply

Your email address will not be published. Required fields are marked *