jQuery > Effects methods

.queue() - Get length of animation queue in jQuery

How to get the number of animation to be executed on a particular element in jQuery?

To get the number of items to be executed on a particular element, queue() method can be used.

<input type="button" id="btnQueue" value="Queue" />
<div id="divQueue" style="height: 50px; width: 50px; background: brown; left: 0px; position: absolute; display: none;"> </div>
<script> $("#btnQueue").click(function () { QueueIt(); var n = $("#divQueue").queue("fx"); alert(n.length); }); function QueueIt() { $("#divQueue").show("slow"); // 1st animation $("#divQueue").slideUp("slow"); // 2nd animation $("#divQueue").slideDown("slow"); // 3rd animation $("#divQueue").hide("fast", QueueIt); // 4th animation }

In the above code, on the click event of the “btnQueue”, a “QueueIt()” function will be called that has four animation to be performed so the alert statement will alert 4 ie. the number of animation to be performed on "divQueue" element.

Note that in the last statement of QueueIt() function, we have specified the “QueueIt” function name in the 2nd parameter of the “hide()” function so a “QueueIt” function will keep executing.

 Views: 4296 | Post Order: 103

Write for us

Hosting Recommendations