jQuery.queue()
The jQuery.queue()
method in jQuery is a low-level method refers to .queue()
.They are used to manipulate the queue of functions to be executed on the matched elements.
jQuery.queue()
syntaxjQuery.queue(element,[queueName]); jQuery.queue(element,queueName,newQueue); jQuery.queue(element,queueName,callback);
Parameter | Type | Description |
---|---|---|
element |
Element | the DOM element |
queueName |
String | the name of the queue. |
newQueue |
Array | An array of functions to replace the current queue contents. |
callback |
Function | The new function to add to the queue |
jQuery.queue(element,[queueName])
Show the queue of functions to be executed on the matched elements.
Get the length of the queue.
Be careful:
jQuery 1.x and 3.x return different values.
var n = jQuery.queue(document.getElementById('content'),"fx" ); console.log( n.length );
jQuery.queue([queueName,][newQueue|callback]);
Manipulate the queue of functions to be executed,it allows us to place a new function at the end of the queue.
$( "#block" ).animate({ left: "+=200" }, 2000 ); jQuery.queue($( "#foo" )[0],"fx",function() { $(this).slideUp(1000).dequeue(this); }); // is equivalent to: $( "#block" ).animate({ left: "+=200" }, 2000 ).slideUp(1000);
$( "#foo" ).slideUp(); jQuery.queue($( "#foo" )[0],"fx",function() { alert( "Animation complete." ); $( this ).dequeue(this); }); // is equivalent to: $( "#foo" ).slideUp(function() { alert( "Animation complete." ); });
Because the addClass
is not a animation, we can use jQuery.queue()
to add it to the functions queue.