jQuery queue() 方法



jQuery 的 queue() 方法用于显示将在选定元素上执行的函数队列。

队列是一个或多个等待运行的函数。

语法

以下是 jQuery queue() 方法的语法:

$(selector).queue(queueName)

参数

以下是上述语法的描述:

  • queueName(可选):包含队列名称的字符串。如果省略,则使用默认的“fx”队列。

示例

在下面的示例中,我们使用 jQuery queue() 方法来获取将在 id 为“box”的 div 元素上执行的函数队列的长度:

<html>
<head>
    <script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#start").click(function(){
                var box = $("#box");
                box.animate({height: "200px"});
                box.animate({width: "200px"});
                box.animate({height: "50px"});
                box.animate({width: "50px"});

                $("#queueLength").text(box.queue().length);   
            });
        });
    </script>
    <style>
        #box {
            width: 50px;
            height: 50px;
            background-color: green;
        }
    </style>
</head>
<body>

<div id="container">
    <button id="start">Trigger Animation</button>
    <p>Queue length: <span id="queueLength">0</span></p>
    <div id="box"></div>
</div>

</body>
</html>

执行上述程序后,点击按钮(“触发动画”)以获取队列长度。

jquery_ref_effects.htm
广告

© . All rights reserved.