jQuery .stop 停止之前的动作,只保留最后一次的动作

in jQuery with 0 comment

停止之前的动嘴,只保留最后一次的动作
.stop的方法

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box{
            width: 200px;
            height: 200px;
            background: gold;
            margin: 100px auto;
        }
    </style>
    <script src="../js/jquery-3.4.1.js"></script>
    <script>
        $(function () {
            var $div = $('.box');

            $div.mouseover(function () {
                $(this).stop().animate({'margin-top':150})

            });
            $div.mouseout(function () {
                $(this).stop().animate({'margin-top':100})

            })


        })
    </script>
</head>
<body>
    <div class="box"></div>
</body>
</html>
Responses