.clearQueue()
.clearQueue( [ queueName ] ) 返回: jQuery
描述: 從列隊(duì)中移除所有未執(zhí)行的項(xiàng)。
-
version added: 1.4.clearQueue( [ queueName ] )
queueName一個(gè)含有隊(duì)列名的字符串。默認(rèn)是"Fx",標(biāo)準(zhǔn)的動畫隊(duì)列。
當(dāng).clearQueue()被訪問的時(shí)候,所有在這個(gè)列隊(duì)中未執(zhí)行的函數(shù)將被移除 。當(dāng)不使用參數(shù)的時(shí)候,.clearQueue()會從標(biāo)準(zhǔn)的動畫隊(duì)列fx中移除剩下的函數(shù)。這個(gè)方法類似.stop(true)。然而.stop()方法只適用在動畫中。.clearQueue()還可以用來移除用.queue()方法添加的普通jQuery列表的所有函數(shù)。
例子:
清空列隊(duì)
<!DOCTYPE html>
<html>
<head>
<style>
div { margin:3px; width:40px; height:40px;
position:absolute; left:0px; top:30px;
background:green; display:none; }
div.newcolor { background:blue; }
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<button id="start">Start</button>
<button id="stop">Stop</button>
<div></div>
<script>$("#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").clearQueue();
$("div").stop();
});</script>
</body>
</html>