Stop Method in jQuery

 <!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Stop Method</title>
    <style>
        #box {
            background: #90ee90;
            border: 1px solid #000000;
            padding: 10px;
            width: 100px;
            height: 100px;
            position: relative;
            /* position property is necessary while using animate function of jQuery */
        }
    </style>
</head>

<body>
    <h1>jQuery Stop Method</h1>
    <div id="box">Hello World</div>
    <br>
    <button id="animateBtn">Animate</button>
    <button id="stopBtn">Stop</button>
    <script src="js/jquery-3.7.1.min.js"></script>
    <script>
        $(document).ready(function () {
            $("#animateBtn").click(function () {
                $("#box").animate({ left: "200px" }, 3000);
                $("#box").animate({ fontSize: "30px" }, 2000);
            });

            $("#stopBtn").click(function () {
                // $("#box").stop();   //Here will stop only First "left" animation(By default, value of stop() is false)
                // $("#box").stop(true);   //Here will stop all above animations
                $("#box").stop(true, true);  //Here animation will reach at Finish point direct
            });
        });
    </script>
</body>

</html>



Comments

Popular posts from this blog

Basic Syntax in jQuery

Event "Target" Property in jQuery