02.06.2013 Views

jQuery 1.4 Animation Techniques - Index of

jQuery 1.4 Animation Techniques - Index of

jQuery 1.4 Animation Techniques - Index of

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Download from Wow! eBook <br />

Managing <strong>Animation</strong>s<br />

When called, it will remove the next function in the queue and execute it. It's a simple<br />

method, with few arguments, and is used in a very specific manner. The method may take a<br />

single optional argument which is the name <strong>of</strong> the queue to execute the next function from:<br />

<strong>jQuery</strong>(elements).dequeue([queue name]);<br />

The queue name is only required if we are working with a queue other than the default fx<br />

queue. We didn't need to provide the name <strong>of</strong> the queue in the previous example in the last<br />

section because we replaced the animated element's default fx queue. The dequeue()<br />

method has the same effect as calling the next() function that we used to keep the queue<br />

moving in the queueInsert.html example from the last section.<br />

Time for action – dequeueing functions<br />

Let's change the queueInsert.html page so that it uses the dequeue() method instead<br />

<strong>of</strong> the next() function to keep the queue moving.<br />

1. Change the code in queueAdd.html so that it appears as follows:<br />

$("#fader").fadeOut(function() {<br />

$(this).queue(function() {<br />

$(this).css("backgroundColor", "green").dequeue();<br />

}).fadeOut();<br />

}).fadeIn().fadeOut().fadeIn();<br />

2. Save this version as dequeue.html.<br />

What just happened?<br />

This time we do not need to pass anything into the callback function passed to the<br />

queue() method. We simply chain the dequeue() method to the after setting its<br />

background-color to green. This has the same effect as before and the green will<br />

fade out at the end <strong>of</strong> the animation.<br />

Stopping an animation<br />

The stop() method can be used to stop an effect that is currently running on the selected<br />

element. In its simplest form, we may call the method without supplying any additional<br />

arguments, but if necessary we can supply up to two Boolean arguments. The method takes<br />

the following format:<br />

<strong>jQuery</strong>(elements).stop([clear queue], [jump to end]);<br />

[ 66 ]

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

Saved successfully!

Ooh no, something went wrong!