jquery 手册
Ajax
属性(Attributes)
回调对象(Callbacks ..
核心(Core)
CSS
数据(Data)
延迟对象(Deferred o ..
尺寸(Dimensions)
效果(Effects)
事件(Events)
表单(Forms)
文档操作(Manipulati ..
杂项(Miscellaneou ..
位置(Offset)
插件编写(Plugin Aut ..
属性(Properties)
选择器(Selectors)
遍历(Traversing)
工具(Utilities)

Returns: ArrayArray jQuery.queue( Element element, String queueName )

描述: 显示在匹配的元素上的未执行的函数列队数.
  • version added: 1.3
  • jQuery.queue( Element element, String queueName )
  • element 一个用于检查附加列队的DOM元素.
    queueName 一个含有队列名的字符串。默认是fx,标准的动画队列.

注意: 这是一个底层的方法,你应该用.queue()代替.

Examples:

例子:

展示队列的长度.
<!DOCTYPE html>
<html>
<head>
  <script src="../jquery.min.js"></script>
  <style>div { margin:3px; width:40px; height:40px;
        position:absolute; left:0px; top:30px; 
        background:green; display:none; }
  div.newcolor { background:blue; }
  span { color:red; }</style>
</head>
<body>
  <button id="show">Show Length of Queue</button>
  <span></span>
  <div></div>
  <script>$("#show").click(function () {
      var n = jQuery.queue( $("div")[0], "fx" );
      $("span").text("Queue length is: " + n.length);
    });
    function runIt() {
      $("div").show("slow");
      $("div").animate({left:'+=200'},2000);
      $("div").slideToggle(1000);
      $("div").slideToggle("fast");
      $("div").animate({left:'-=200'},1500);
      $("div").hide("slow");
      $("div").show(1200);
      $("div").slideUp("normal", runIt);
    }
    runIt();</script>
</body>
</html>

Demo:

Returns: jQueryjQuery jQuery.queue( Element element, String queueName, Function callback() )

Description: Manipulate the queue of functions to be executed on the matched element.
  • version added: 1.3
  • jQuery.queue( Element element, String queueName, Array newQueue )
  • element 一个已附加列队函数的DOM元素.
    queueName 一个含有队列名的字符串。默认是"Fx",标准的动画队列.
    newQueue 函数数组,用于替换当前的队列内容.
  • version added: 1.3
  • jQuery.queue( Element element, String queueName, Function callback() )
  • element 一个要附加列队函数的DOM元素.
    queueName 一个含有队列名的字符串。默认是fx,标准的动画队列.
    callback() 添加到列队的新函数.

注意:这是一个底层的方法,你应该用.queue()代替.

Every element can have one or more queues of functions attached to it by jQuery. In most applications, only one queue (called fx) is used. Queues allow a sequence of actions to be called on an element asynchronously, without halting program execution.

The jQuery.queue() method allows us to directly manipulate this queue of functions. Calling jQuery.queue() with a callback is particularly useful; it allows us to place a new function at the end of the queue.

Note that when adding a function with jQuery.queue(), we should ensure that jQuery.dequeue() is eventually called so that the next function in line executes.

Examples:

Example:

Queue a custom function.
<!DOCTYPE html>
<html>
<head>
  <script src="../jquery.min.js"></script>
  <style>div { margin:3px; width:40px; height:40px;
        position:absolute; left:0px; top:30px; 
        background:green; display:none; }
  div.newcolor { background:blue; }</style>
</head>
<body>
  Click here...
  <div></div>
  <script>$(document.body).click(function () {
      $("div").show("slow");
      $("div").animate({left:'+=200'},2000);
      jQuery.queue( $("div")[0], "fx", function () {
        $(this).addClass("newcolor");
        jQuery.dequeue( this );
      });
      $("div").animate({left:'-=200'},500);
      jQuery.queue( $("div")[0], "fx", function () {
        $(this).removeClass("newcolor");
        jQuery.dequeue( this );
      });
      $("div").slideUp();
    });</script>
</body>
</html>

Demo:

Example:

Set a queue array to delete the queue.
<!DOCTYPE html>
<html>
<head>
  <script src="../jquery.min.js"></script>
  <style>div { margin:3px; width:40px; height:40px;
        position:absolute; left:0px; top:30px; 
        background:green; display:none; }
  div.newcolor { background:blue; }</style>
</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);
      jQuery.queue( $("div")[0], "fx", function () {
        $(this).addClass("newcolor");
        jQuery.dequeue( this );
      });
      $("div").animate({left:'-=200'},1500);
      jQuery.queue( $("div")[0], "fx", function () {
        $(this).removeClass("newcolor");
        jQuery.dequeue( this );
      });
      $("div").slideUp();
    });
    $("#stop").click(function () {
      jQuery.queue( $("div")[0], "fx", [] );
      $("div").stop();
    });</script>
</body>
</html>

Demo: