显示或操作在匹配元素上执行的函数队列
参数
element,[queueName]
element:检查附加列队的DOM元素
queueName:字符串值,包含序列的名称。默认是 fx, 标准的效果序列。
element,queueName,newQueue Element,String,Array
element:检查附加列队的DOM元素
queueName:字符串值,包含序列的名称。默认是 fx, 标准的效果序列。
newQueue:替换当前函数列队内容的数组
element,queueName,callback()Element,String
element:检查附加列队的DOM元素
queueName:字符串值,包含序列的名称。默认是 fx, 标准的效果序列。
callback():要添加进队列的函数
示例
描述:
显示队列长度
HTML 代码:
<style>
div { margin:3px; width:40px; height:40px;
position:absolute; left:0px; top:30px;
background:green; display:none; }
div.newcolor { background:blue; }
span { color:red; }
</style>
<button id="show">Show Length of Queue</button>
<span></span>
<div></div>jQuery 代码:
$("#show").click(function () {
var n = $("div").queue("fx");
$("span").text("Queue length is: " + n.length);
});
function runIt() {
$("div").show("slow");
$("div").animate({left:'+=200'},2000);
$("div").slideToggle(1000);
$("div").slideToggle("fast");
$("div").animate({left:'-=200'},1500);
$("div").hide("slow");
$("div").show(1200);
$("div").slideUp("normal", runIt);
}
runIt();描述:
通过设定队列数组来删除动画队列
HTML 代码:
<style>
div { margin:3px; width:40px; height:40px;
position:absolute; left:0px; top:30px;
background:green; display:none; }
div.newcolor { background:blue; }
</style>
<button id="start">Start</button>
<button id="stop">Stop</button>
<div></div>jQuery 代码:
$("#start").click(function () {
$("div").show("slow");
$("div").animate({left:'+=200'},5000);
$("div").queue(function () {
$(this).addClass("newcolor");
$(this).dequeue();
});
$("div").animate({left:'-=200'},1500);
$("div").queue(function () {
$(this).removeClass("newcolor");
$(this).dequeue();
});
$("div").slideUp();
});
$("#stop").click(function () {
$("div").queue("fx", []);
$("div").stop();
});描述:
插入一个自定义函数 如果函数执行后要继续队列,则执行 jQuery(this).dequeue();
HTML 代码:
<style>
div { margin:3px; width:40px; height:40px;
position:absolute; left:0px; top:30px;
background:green; display:none; }
div.newcolor { background:blue; }
</style>
Click here...
<div></div>jQuery 代码:
$(document.body).click(function () {
$("div").show("slow");
$("div").animate({left:'+=200'},2000);
$("div").queue(function () {
$(this).addClass("newcolor");
$(this).dequeue();
});
$("div").animate({left:'-=200'},500);
$("div").queue(function () {
$(this).removeClass("newcolor");
$(this).dequeue();
});
$("div").slideUp();
});删除队列
dequeue
从队列最前端移除一个队列函数,并执行他。
参数
[queueName]String
队列名,默认为fx
示例
描述:
使用 dequeue() 终止一个自定义的队列函数
jQuery 代码:
$("div").queue(function () {
$(this).toggleClass("red");
$(this).dequeue();
});描述:
用dequeue来结束自定义队列函数,并让队列继续进行下去。
HTML 代码:
<style>
div { margin:3px; width:50px; position:absolute;
height:50px; left:10px; top:30px;
background-color:yellow; }
div.red { background-color:red; }
</style>
<button>Start</button>
<div></div>jQuery 代码:
$("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);
});清空尚未执行的队列clearQueue
清空对象上尚未执行的所有队列
如果不带参数,则默认清空的是动画队列。这跟stop(true)类似,但stop()只能清空动画队列,而这个可以清空所有通过 .queue() 创建的队列。
参数
queueName Boolean
含有队列名的字符串。默认是"Fx",动画队列。
示例
描述:
停止当前正在运行的动画:
jQuery 代码:
$("#stop").click(function(){
$("#box").clearQueue();
});