.clearQueue()

.clearQueue( [ queueName ] ) 官网原E文: jQuery

描述: 从列队中移除所有未执行的项。

  • version added: 1.4.clearQueue( [ queueName ] )

    queueName一个含有队列名的字符串。默认是"Fx",标准的动画队列。

.clearQueue()被访问的时候,所有在这个列队中未执行的函数将被移除 。当不使用参数的时候,.clearQueue()会从标准的动画队列fx中移除剩下的函数。这个方法类似.stop(true)。然而.stop()方法只适用在动画中。.clearQueue()还可以用来移除用.queue()方法添加的普通jQuery列表的所有函数。

例子:

清空列队

<!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>

Demo:

jQuery 1.6 API 中文版Clove整理、修订