jQuery clearQueue() 方法停止队列中所有仍未执行的函数

jQuery实例

停止当前正在运行的动画:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#start").click(function(){
$("#box").animate({height:300},"slow");
$("#box").animate({width:300},"slow");
$("#box").queue(function () {
$(this).css("background-color","red");
$(this).dequeue();
});
$("#box").animate({height:100},"slow");
$("#box").animate({width:100},"slow");
});
$("#stop").click(function(){
$("#box").clearQueue();
});
});
</script>
</head>
<body>

<p><button id="start">Start Animation</button><button id="stop">Stop Animation</button></p>
<div id="box" style="background:#98bf21;height:100px;width:100px;position:relative">
</div>

</body>
</html>

定义和用法

clearQueue() 方法停止队列中所有仍未执行的函数。

与 stop() 方法不同,(只适用于动画),clearQueue() 能够清除任何排队的函数(通过 .queue() 方法添加到通用 jQuery 队列的任何函数)。

语法

$(selector).clearQueue(queueName)

参数

描述

queueName

可选。规定要停止的队列的名称。

默认是 "fx",标准效果队列。

 

THE END