jQuery 1.4 Animation Techniques - Index of

jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of

02.06.2013 Views

If we wish to see how many functions are left in the queue (including the one that is in progress), we could change the console.log line to this: console.log($(this).queue().length); This code would show the following output in Firebug's console: This time our console shows numerically how many items are left in the queue, as shown in the previous screenshot. [ 59 ] Chapter 3 We can use other array methods on the queue if we wish (although this would rarely be useful), such as push() or pop() to add or remove items for example. We can also get a single item from the queue if we wish, by adding square braces and an index number after the call to queue(): console.log($(this).queue()[1]); As shown above, this time the value of the second item is output to the console. As I mentioned earlier, we can see the actual contents of the function using the toString() JavaScript function: console.log($(this).queue()[1].toString);

Managing Animations Running this code produces the following output: The code shown in the previous screenshot won't make much sense to the casual observer as it's been minified, but it's the contents of jQuery's fadeout() method. Pop quiz – viewing the queue 1. What is the easiest way of determining the number of functions in the queue? a. Using the length() method b. Using the length property c. Counting them in Firebug d. By looking at the effectsLeftToRun property of the animated element's fx queue [ 60 ]

If we wish to see how many functions are left in the queue (including the one that is in<br />

progress), we could change the console.log line to this:<br />

console.log($(this).queue().length);<br />

This code would show the following output in Firebug's console:<br />

This time our console shows numerically how many items are left in the queue, as shown<br />

in the previous screenshot.<br />

[ 59 ]<br />

Chapter 3<br />

We can use other array methods on the queue if we wish (although this would rarely be<br />

useful), such as push() or pop() to add or remove items for example. We can also get a<br />

single item from the queue if we wish, by adding square braces and an index number after<br />

the call to queue():<br />

console.log($(this).queue()[1]);<br />

As shown above, this time the value <strong>of</strong> the second item is output to the console. As I<br />

mentioned earlier, we can see the actual contents <strong>of</strong> the function using the toString()<br />

JavaScript function:<br />

console.log($(this).queue()[1].toString);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!