PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/1.6/docs/queue/index.html

https://github.com/mustardamus/jquery-api-scrape
HTML | 222 lines | 207 code | 15 blank | 0 comment | 0 complexity | 893b1ff3b89f628f2cc26fc2e5ba700b MD5 | raw file
  1. <!DOCTYPE html>
  2. <html lang='en'><head><meta http-equiv='content-type' content='text/html; charset=UTF-8' /></head><body>
  3. <div class="entry-content">
  4. <div class="entry-title roundTop">
  5. <h1 class="jq-clearfix">.queue()</h1>
  6. <div class="entry-meta jq-clearfix">
  7. Categories:
  8. <span class="category"><a href="http://api.jquery.com/category/effects/" title="View all posts in Effects">Effects</a> &gt; <a href="http://api.jquery.com/category/effects/custom-effects/" title="View all posts in Custom">Custom</a></span> | <span class="category"><a href="http://api.jquery.com/category/data/" title="View all posts in Data">Data</a></span> | <span class="category"><a href="http://api.jquery.com/category/utilities/" title="View all posts in Utilities">Utilities</a></span>
  9. </div>
  10. </div>
  11. <div class="toc">
  12. <h4><span>Contents:</span></h4>
  13. <ul class="toc-list">
  14. <li>
  15. <a href="#queue1">queue( [ queueName ]  ) </a><ul><li>.queue( [queueName] )
  16. </li></ul>
  17. </li>
  18. <li>
  19. <a href="#queue2">queue( [ queueName, ] newQueue  ) </a><ul>
  20. <li>.queue( [queueName,] newQueue )
  21. </li>
  22. <li>.queue( [queueName,] callback( next ) )
  23. </li>
  24. </ul>
  25. </li>
  26. </ul>
  27. </div>
  28. <div id="queue1" class="entry method">
  29. <h2 class="jq-clearfix roundTop section-title">
  30. <span class="name">.queue( [queueName] )</span> <span class="returns">Returns: <a class="return" href="http://api.jquery.com/Types/#Array">Array</a></span>
  31. </h2>
  32. <div class="jq-box roundBottom entry-details">
  33. <p class="desc"><strong>Description: </strong>Show the queue of functions to be executed on the matched elements.</p>
  34. <ul class="signatures"><li class="signature" id="queue-queueName">
  35. <h4 class="name">
  36. <span class="versionAdded">version added: <a href="/category/version/1.2/">1.2</a></span>.queue( [queueName] )</h4>
  37. <p class="arguement"><strong>queueName</strong>A string containing the name of the queue. Defaults to <code>fx</code>, the standard effects queue.</p>
  38. </li></ul>
  39. <h3>Example:</h3>
  40. <div class="entry-examples" id="entry-examples"><div id="example-0">
  41. <h4><span class="desc">Show the length of the queue.</span></h4>
  42. <pre class="prettyprint"><code class="example demo-code">&lt;!DOCTYPE html&gt;
  43. &lt;html&gt;
  44. &lt;head&gt;
  45. &lt;style&gt;div { margin:3px; width:40px; height:40px;
  46. position:absolute; left:0px; top:60px;
  47. background:green; display:none; }
  48. div.newcolor { background:blue; }
  49. p { color:red; } &lt;/style&gt;
  50. &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
  51. &lt;/head&gt;
  52. &lt;body&gt;
  53. &lt;p&gt;The queue length is: &lt;span&gt;&lt;/span&gt;&lt;/p&gt;
  54. &lt;div&gt;&lt;/div&gt;
  55. &lt;script&gt;
  56. var div = $("div");
  57. function runIt() {
  58. div.show("slow");
  59. div.animate({left:'+=200'},2000);
  60. div.slideToggle(1000);
  61. div.slideToggle("fast");
  62. div.animate({left:'-=200'},1500);
  63. div.hide("slow");
  64. div.show(1200);
  65. div.slideUp("normal", runIt);
  66. }
  67. function showIt() {
  68. var n = div.queue("fx");
  69. $("span").text( n.length );
  70. setTimeout(showIt, 100);
  71. }
  72. runIt();
  73. showIt();
  74. &lt;/script&gt;
  75. &lt;/body&gt;
  76. &lt;/html&gt;</code></pre>
  77. <h4>Demo:</h4>
  78. <div class="demo code-demo"></div>
  79. </div></div>
  80. </div>
  81. </div>
  82. <div id="queue2" class="entry method">
  83. <h2 class="jq-clearfix roundTop section-title">
  84. <span class="name">.queue( [queueName,] newQueue )</span> <span class="returns">Returns: <a class="return" href="http://api.jquery.com/Types/#jQuery">jQuery</a></span>
  85. </h2>
  86. <div class="jq-box roundBottom entry-details">
  87. <p class="desc"><strong>Description: </strong>Manipulate the queue of functions to be executed on the matched elements.</p>
  88. <ul class="signatures">
  89. <li class="signature" id="queue-queueName-newQueue">
  90. <h4 class="name">
  91. <span class="versionAdded">version added: <a href="/category/version/1.2/">1.2</a></span>.queue( [queueName], newQueue )</h4>
  92. <p class="arguement"><strong>queueName</strong>A string containing the name of the queue. Defaults to <code>fx</code>, the standard effects queue.</p>
  93. <p class="arguement"><strong>newQueue</strong>An array of functions to replace the current queue contents.</p>
  94. </li>
  95. <li class="signature" id="queue-queueName-callback next ">
  96. <h4 class="name">
  97. <span class="versionAdded">version added: <a href="/category/version/1.2/">1.2</a></span>.queue( [queueName], callback( next ) )</h4>
  98. <p class="arguement"><strong>queueName</strong>A string containing the name of the queue. Defaults to <code>fx</code>, the standard effects queue.</p>
  99. <p class="arguement"><strong>callback( next )</strong>The new function to add to the queue, with a function to call that will dequeue the next item.</p>
  100. </li>
  101. </ul>
  102. <div class="longdesc">
  103. <p>Every element can have one to many queues of functions attached to it by jQuery. In most applications, only one queue (called <code>fx</code>) is used. Queues allow a sequence of actions to be called on an element asynchronously, without halting program execution. The typical example of this is calling multiple animation methods on an element. For example:</p>
  104. <pre>$('#foo').slideUp().fadeIn();</pre>
  105. <p>When this statement is executed, the element begins its sliding animation immediately, but the fading transition is placed on the <code>fx</code> queue to be called only once the sliding transition is complete.</p>
  106. <p>The <code>.queue()</code> method allows us to directly manipulate this queue of functions. Calling <code>.queue()</code> with a callback is particularly useful; it allows us to place a new function at the end of the queue.</p>
  107. <p>This feature is similar to providing a callback function with an animation method, but does not require the callback to be given at the time the animation is performed.</p>
  108. <pre>$('#foo').slideUp();
  109. $('#foo').queue(function() {
  110. alert('Animation complete.');
  111. $(this).dequeue();
  112. });</pre>
  113. <p>This is equivalent to:</p>
  114. <pre>$('#foo').slideUp(function() {
  115. alert('Animation complete.');
  116. });</pre>
  117. <p>Note that when adding a function with <code>.queue()</code>, we should ensure that <code>.dequeue()</code> is eventually called so that the next function in line executes.</p>
  118. <p>In jQuery 1.4 the function that's called is passed in another function, as the first argument, that when called automatically dequeues the next item and keeps the queue moving. You would use it like so:</p>
  119. <pre>$("#test").queue(function(next) {
  120. // Do some stuff...
  121. next();
  122. });</pre>
  123. </div>
  124. <h3>Examples:</h3>
  125. <div class="entry-examples" id="entry-examples-1">
  126. <div id="example-1-0">
  127. <h4>Example: <span class="desc">Queue a custom function.</span>
  128. </h4>
  129. <pre class="prettyprint"><code class="example demo-code">&lt;!DOCTYPE html&gt;
  130. &lt;html&gt;
  131. &lt;head&gt;
  132. &lt;style&gt;
  133. div { margin:3px; width:40px; height:40px;
  134. position:absolute; left:0px; top:30px;
  135. background:green; display:none; }
  136. div.newcolor { background:blue; }
  137. &lt;/style&gt;
  138. &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
  139. &lt;/head&gt;
  140. &lt;body&gt;
  141. Click here...
  142. &lt;div&gt;&lt;/div&gt;
  143. &lt;script&gt;$(document.body).click(function () {
  144. $("div").show("slow");
  145. $("div").animate({left:'+=200'},2000);
  146. $("div").queue(function () {
  147. $(this).addClass("newcolor");
  148. $(this).dequeue();
  149. });
  150. $("div").animate({left:'-=200'},500);
  151. $("div").queue(function () {
  152. $(this).removeClass("newcolor");
  153. $(this).dequeue();
  154. });
  155. $("div").slideUp();
  156. });&lt;/script&gt;
  157. &lt;/body&gt;
  158. &lt;/html&gt;</code></pre>
  159. <h4>Demo:</h4>
  160. <div class="demo code-demo"></div>
  161. </div>
  162. <div id="example-1-1">
  163. <h4>Example: <span class="desc">Set a queue array to delete the queue.</span>
  164. </h4>
  165. <pre class="prettyprint"><code class="example demo-code">&lt;!DOCTYPE html&gt;
  166. &lt;html&gt;
  167. &lt;head&gt;
  168. &lt;style&gt;
  169. div { margin:3px; width:40px; height:40px;
  170. position:absolute; left:0px; top:30px;
  171. background:green; display:none; }
  172. div.newcolor { background:blue; }
  173. &lt;/style&gt;
  174. &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
  175. &lt;/head&gt;
  176. &lt;body&gt;
  177. &lt;button id="start"&gt;Start&lt;/button&gt;
  178. &lt;button id="stop"&gt;Stop&lt;/button&gt;
  179. &lt;div&gt;&lt;/div&gt;
  180. &lt;script&gt;$("#start").click(function () {
  181. $("div").show("slow");
  182. $("div").animate({left:'+=200'},5000);
  183. $("div").queue(function () {
  184. $(this).addClass("newcolor");
  185. $(this).dequeue();
  186. });
  187. $("div").animate({left:'-=200'},1500);
  188. $("div").queue(function () {
  189. $(this).removeClass("newcolor");
  190. $(this).dequeue();
  191. });
  192. $("div").slideUp();
  193. });
  194. $("#stop").click(function () {
  195. $("div").queue("fx", []);
  196. $("div").stop();
  197. });&lt;/script&gt;
  198. &lt;/body&gt;
  199. &lt;/html&gt;</code></pre>
  200. <h4>Demo:</h4>
  201. <div class="demo code-demo"></div>
  202. </div>
  203. </div>
  204. </div>
  205. </div>
  206. </div>
  207. </body></html>