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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Time for action – exploding an element<br />

In this example we will make an image explode.<br />

1. Just add the following simple image to the <strong>of</strong> the template file:<br />

<br />

[ 163 ]<br />

Chapter 6<br />

2. Then add the following equally simple code to the empty function at the bottom <strong>of</strong><br />

the template file:<br />

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

$(this).effect("explode");<br />

});<br />

3. Save this page as explode.html.<br />

4. This example is so simple we don't even need a stylesheet. Once we click on the<br />

grenade, it is exploded into the default number <strong>of</strong> pieces:<br />

The exploded element fades away as the individual pieces <strong>of</strong> the element move apart.<br />

What just happened?<br />

In the example, all we need to do is attach a click handler directly to the image which applies<br />

the explode effect using the effect() method. No configuration in this instance is required<br />

because the default mode <strong>of</strong> the effect is hide.<br />

Note that we can also run this effect in reverse by setting the mode option to show, or using<br />

the show() logic instead. In this scenario, we will see the target element constructed from a<br />

series <strong>of</strong> pieces that fade in and fly together—an explosion in reverse.

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

Saved successfully!

Ooh no, something went wrong!