将匹配元素的队列用新的一个队列来代替(函数数组)
返回值
jQuery
参数
name(String):队列名,默认为fx
queue(Array<Function>):用于替换的队列。所有函数都有同一个参数,这个值与queue(callback)相同
示例
通过设定队列数组来删除动画队列
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();
});