.queue()
The .queue()
method in jQuery is used to manipulate the queue of functions to be executed on the matched elements.
.queue()
syntax.queue([queueName]); .queue([queueName,]newQueue); .queue([queueName,]callback);
Parameter | Type | Description |
---|---|---|
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 |
.queue([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 = div.queue( "fx" ); console.log( n.length );
.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 ).queue(function() {$(this).slideUp(1000).dequeue()}); // is equivalent to: $( "#block" ).animate({ left: "+=200" }, 2000 ).slideUp(1000);
$( "#foo" ).slideUp(); $( "#foo" ).queue(function() { alert( "Animation complete." ); $( this ).dequeue(); }); // is equivalent to: $( "#foo" ).slideUp(function() { alert( "Animation complete." ); });
Because the addClass
is not a animation, we can use queue()
to add it to the queue.