1 line
5.1 KiB
JSON
1 line
5.1 KiB
JSON
{"name":"jQuery.queue","type":"method","title":"jQuery.queue()","deprecated":null,"removed":null,"desc":"Show or manipulate the queue of functions to be executed on the matched element.","categories":["data","utilities","version/1.3"],"entries":[{"return":"Array","signatures":{"added":"1.3","argument":[{"desc":"A DOM element to inspect for an attached queue.","name":"element","type":"Element"},{"desc":"A string containing the name of the queue. Defaults to <code>fx</code>, the standard effects queue.","name":"queueName","optional":"true","type":"String"}]},"examples":{"desc":"Show the length of the queue.","code":"\n$( \"#show\" ).click(function() {\n var n = jQuery.queue( $( \"div\" )[ 0 ], \"fx\" );\n $( \"span\" ).text( \"Queue length is: \" + n.length );\n});\n\nfunction runIt() {\n $( \"div\" )\n .show( \"slow\" )\n .animate({\n left: \"+=200\"\n }, 2000 )\n .slideToggle( 1000 )\n .slideToggle( \"fast\" )\n .animate({\n left: \"-=200\"\n }, 1500 )\n .hide( \"slow\" )\n .show( 1200 )\n .slideUp( \"normal\", runIt );\n}\n\nrunIt();\n","css":"\n div {\n margin: 3px;\n width: 40px;\n height: 40px;\n position: absolute;\n left: 0px;\n top: 30px;\n background: green;\n display: none;\n }\n div.newcolor {\n background: blue;\n }\n span {\n color: red;\n }\n","html":"\n<button id=\"show\">Show Length of Queue</button>\n<span></span>\n<div></div>\n "},"desc":"Show the queue of functions to be executed on the matched element.","longdesc":"\n <p><strong>Note:</strong> This is a low-level method, you should probably use <code><a href=\"/queue/\">.queue()</a></code> instead.</p>\n "},{"return":"jQuery","signatures":[{"added":"1.3","argument":[{"desc":"A DOM element where the array of queued functions is attached.","name":"element","type":"Element"},{"desc":"A string containing the name of the queue. Defaults to <code>fx</code>, the standard effects queue.","name":"queueName","type":"String"},{"desc":"An array of functions to replace the current queue contents.","name":"newQueue","type":"Array"}]},{"added":"1.3","argument":[{"desc":"A DOM element on which to add a queued function.","name":"element","type":"Element"},{"desc":"A string containing the name of the queue. Defaults to <code>fx</code>, the standard effects queue.","name":"queueName","type":"String"},{"desc":"The new function to add to the queue.","name":"callback()","type":"Function"}]}],"examples":[{"desc":"Queue a custom function.","code":"\n$( document.body ).click(function() {\n var divs = $( \"div\" )\n .show( \"slow\" )\n .animate({ left: \"+=200\" }, 2000 );\n jQuery.queue( divs[ 0 ], \"fx\", function() {\n $( this ).addClass( \"newcolor\" );\n jQuery.dequeue( this );\n });\n divs.animate({ left: \"-=200\" }, 500 );\n jQuery.queue( divs[ 0 ], \"fx\", function() {\n $( this ).removeClass( \"newcolor\" );\n jQuery.dequeue( this );\n });\n divs.slideUp();\n});\n","css":"\n div {\n margin: 3px;\n width: 40px;\n height: 40px;\n position: absolute;\n left: 0px;\n top: 30px;\n background: green;\n display: none;\n }\n div.newcolor {\n background: blue;\n }\n","html":"\nClick here...\n<div></div>\n"},{"desc":"Set a queue array to delete the queue.","code":"\n$( \"#start\" ).click(function() {\n var divs = $( \"div\" )\n .show( \"slow\" )\n .animate({ left: \"+=200\" }, 5000 );\n jQuery.queue( divs[ 0 ], \"fx\", function() {\n $( this ).addClass( \"newcolor\" );\n jQuery.dequeue( this );\n });\n divs.animate({ left: \"-=200\" }, 1500 );\n jQuery.queue( divs[ 0 ], \"fx\", function() {\n $( this ).removeClass( \"newcolor\" );\n jQuery.dequeue( this );\n });\n divs.slideUp();\n});\n$( \"#stop\" ).click(function() {\n jQuery.queue( $( \"div\" )[ 0 ], \"fx\", [] );\n $( \"div\" ).stop();\n});\n","css":"\n div {\n margin: 3px;\n width: 40px;\n height: 40px;\n position: absolute;\n left: 0px;\n top: 30px;\n background: green;\n display: none;\n }\n div.newcolor {\n background: blue;\n }\n","html":"\n<button id=\"start\">Start</button>\n<button id=\"stop\">Stop</button>\n<div></div>\n"}],"desc":"Manipulate the queue of functions to be executed on the matched element.","longdesc":"\n <p><strong>Note:</strong> This is a low-level method, you should probably use <code><a href=\"/queue/\">.queue()</a></code> instead.</p>\n <p>Every element can have one or more 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.</p>\n <p>The <code>jQuery.queue()</code> method allows us to directly manipulate this queue of functions. Calling <code>jQuery.queue()</code> with a callback is particularly useful; it allows us to place a new function at the end of the queue.</p>\n <p>Note that when adding a function with <code>jQuery.queue()</code>, we should ensure that <code>jQuery.dequeue()</code> is eventually called so that the next function in line executes.</p>\n "}]} |