jQuery 数据 - dequeue() 方法 概述
jQuery 2022-06-01 18:41:0517小码哥的IT人生shichen
jQuery 数据 - dequeue() 方法
实例
使用 dequeue() 终止一个自定义的队列函数:
$("div").queue(function () { $(this).toggleClass("red"); $(this).dequeue(); });
完整实例:
<!DOCTYPE html> <html> <head> <style> div { margin:3px; width:50px; position:absolute; height:50px; left:10px; top:30px; background-color:yellow; } div.red { background-color:red; } </style> <script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script> </head> <body> <button>开始</button> <div></div> <script> $("button").click(function () { $("div").animate({left:'+=200px'}, 2000); $("div").animate({top:'0px'}, 600); $("div").queue(function () { $(this).toggleClass("red"); $(this).dequeue(); }); $("div").animate({left:'10px', top:'30px'}, 700); }); </script> </body> </html>
可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html
定义和用法
dequeue() 方法为匹配元素执行序列中的下一个函数。
语法
.dequeue(queueName)
参数 | 描述 |
---|---|
queueName | 可选。字符串值,包含序列的名称。默认是 fx, 标准的效果序列。 |
详细说明
当调用 .dequeue() 时,会从序列中删除下一个函数,然后执行它。该函数反过来会(直接或间接地)引发对 .dequeue() 的调用,这样序列才能继续下去。