.clearQueue()
返回: jQuery
.clearQueue( [queueName ] )
描述:从队列中删除所有还没有运行过的项目。
如果调用了.clearQueue()方法,所有的队列中的还没有执行的函数将从队列中删除。如果使用时不带参数,.clearQueue()会从fx队列,即标准效果队列中删除剩余的函数。这个方法近似于.stop(true)。然而,.stop()方法意味着只用于动画,与此同时.clearQueue()方法可以用于删除所有的用.queue()方法添加到一般jQuery数列中的函数。
示例
清空队列。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>clearQueue demo</title>
<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="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<button id="start">Start</button>
<button id="stop">Stop</button>
<div></div>
<script>
$( "#start" ).click(function() {
var myDiv = $( "div" );
myDiv.show( "slow" );
myDiv.animate({
left:"+=200"
}, 5000 );
myDiv.queue(function() {
var that = $( this );
that.addClass( "newcolor" );
that.dequeue();
});
myDiv.animate({
left:"-=200"
}, 1500 );
myDiv.queue(function() {
var that = $( this );
that.removeClass( "newcolor" );
that.dequeue();
});
myDiv.slideUp();
});
$( "#stop" ).click(function() {
var myDiv = $( "div" );
myDiv.clearQueue();
myDiv.stop();
});
</script>
</body>
</html>
演示结果