首页 > Web开发 > 详细

jQuery-stop方法

时间:2020-05-21 23:10:24      阅读:52      评论:0      收藏:0      [点我收藏+]

1.stop()方法解析

  • 停止所有在指定元素上正在运行的动画
  • stop(clearQueue,gotoEnd)
  • 这个两个参数可选值是布尔值
  • stop(flase,flase):不请空动画队列,不立即跳到动画最后
  • stop(true,true):请空动画队列,立即跳到动画最后
  • stop(flase,true):不请空动画队列,立即跳到动画最后
  • stop(true,flase):请空动画队列,不立即跳到动画最后

2.代码如下

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>stop用法</title>
    <style>
        #box {
            width: 100px;
            height: 100px;
            position: absolute;
            top: 50px;
            left: 50px;
            border: 1px solid #000;
        }
    </style>
</head>


<body>
    <button id="btn1">stop(false,false)</button>
    <button id="btn2">stop(true,true)</button>
    <button id="btn3">stop(false,true)</button>
    <button id="btn4">stop(true,false)</button>
    <div id="box"></div>
    <script src=" https://cdn.bootcss.com/jquery/3.5.0/jquery.min.js"></script>
    <script>
        var box = $("#box")
        box.animate({
            left: 300
        }, 1000)
        box.animate({
            top: 300
        }, 1000)
        box.animate({
            left: 50
        }, 1000)
        box.animate({
                top: 50
            }, 1000)
            //stop(flase,flase):不请空动画队列,不立即跳到动画最后
        $("#btn1").click(function() {
                box.stop(false, false)
            })
            // stop(true,true):请空动画队列,立即跳到动画最后
        $("#btn2").click(function() {
                box.stop(true, true)
            })
            // stop(flase,true):不请空动画队列,立即跳到动画最后
        $("#btn3").click(function() {
                box.stop(false, true)
            })
            // stop(true,flase):请空动画队列,不立即跳到动画最后
        $("#btn4").click(function() {
            box.stop(true, false)
        })
    </script>
</body>

</html>

jQuery-stop方法

原文:https://www.cnblogs.com/dongxuelove/p/12933765.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!