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.

[ 67 ]<br />

Chapter 3<br />

The first argument clears the element's queue and the second forces the final state <strong>of</strong> the<br />

effect to be applied.<br />

The stop() method behaves differently depending on whether there are any additional<br />

effects in the fx queue.<br />

When the method is called and there are no functions in the queue, any effects that are<br />

currently running on the selected element(s) will simply stop and the element will remain in<br />

whatever state it reached during the animation.<br />

If there are several functions in the queue however, the current animation will be stopped<br />

in whatever state it is in at the time, but then the remaining functions in the queue will<br />

be executed.<br />

Take the following code for example:<br />

$("#fader").fadeOut(5000).fadeIn().fadeOut().fadeIn();<br />

$("#stop").click(function() {<br />

$("#fader").stop();<br />

});<br />

If the stop element is clicked while the first effect is running, the fader element will flicker as<br />

the remaining effects are applied one after the other.<br />

To prevent the queued functions being executed, we can supply true as the value <strong>of</strong> the first<br />

argument. To force the element into its final state, we can also supply true as the value <strong>of</strong><br />

the second argument. Both arguments default to false.<br />

The stop() method can be really useful for preventing animation build-up. If an animation<br />

is triggered by clicking a button for example and the button is clicked repeatedly, the<br />

animation can run multiple times. Usually this behavior is undesirable and can be prevented<br />

using the stop() method.<br />

To see the differences between each variation <strong>of</strong> the stop() method, see<br />

the stopTest.html file in the accompanying code download for this book.

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

Saved successfully!

Ooh no, something went wrong!