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

Time for action – exploding an element In this example we will make an image explode. 1. Just add the following simple image to the of the template file: [ 163 ] Chapter 6 2. Then add the following equally simple code to the empty function at the bottom of the template file: $("img").click(function() { $(this).effect("explode"); }); 3. Save this page as explode.html. 4. This example is so simple we don't even need a stylesheet. Once we click on the grenade, it is exploded into the default number of pieces: The exploded element fades away as the individual pieces of the element move apart. What just happened? In the example, all we need to do is attach a click handler directly to the image which applies the explode effect using the effect() method. No configuration in this instance is required because the default mode of the effect is hide. Note that we can also run this effect in reverse by setting the mode option to show, or using the show() logic instead. In this scenario, we will see the target element constructed from a series of pieces that fade in and fly together—an explosion in reverse.

Extended Animations with jQuery UI The fold effect The fold effect simulates something being folded in half along one axis and then folded in half along the other axis. Of course, the element isn't actually folded in the 3D sense, first one side of the element moves up a specified amount, then another side is moved in and the element disappears. By default the effect uses the hide mode so it will automatically be hidden at the end of the animation. The element being folded is not scaled; it is clipped instead so images and text will not squash up as the effect runs. Configuration options The fold effect exposes three configurable options which are shown in the following table: Option Default Usage horizFirst false Sets whether the element is clipped along the horizontal axis first or not. mode "hide" Sets whether the element is shown or hidden when used with the effect() method. Other values may include show, effect, or toggle. Size 15 This sets the distance of the first fold in pixels and can take either an integer, or a string specifying a value, such as a percentage. Time for action – folding an element away In this example, we'll apply the effect to a simple image of a piece of paper. 1. All we need is an image; add the following code to the of the template file: 2. Next add the following simple script to the bottom of the page, in the empty function as with previous examples: $("img").click(function() { $(this).effect("fold", { size: "50%" }, 1000); }); 3. Save this file as fold.html. [ 164 ]

Extended <strong>Animation</strong>s with <strong>jQuery</strong> UI<br />

The fold effect<br />

The fold effect simulates something being folded in half along one axis and then folded in<br />

half along the other axis. Of course, the element isn't actually folded in the 3D sense, first<br />

one side <strong>of</strong> the element moves up a specified amount, then another side is moved in and<br />

the element disappears.<br />

By default the effect uses the hide mode so it will automatically be hidden at the end <strong>of</strong> the<br />

animation. The element being folded is not scaled; it is clipped instead so images and text<br />

will not squash up as the effect runs.<br />

Configuration options<br />

The fold effect exposes three configurable options which are shown in the following table:<br />

Option Default Usage<br />

horizFirst false Sets whether the element is clipped along the horizontal axis first<br />

or not.<br />

mode "hide" Sets whether the element is shown or hidden when used with the<br />

effect() method. Other values may include show, effect,<br />

or toggle.<br />

Size 15 This sets the distance <strong>of</strong> the first fold in pixels and can take either<br />

an integer, or a string specifying a value, such as a percentage.<br />

Time for action – folding an element away<br />

In this example, we'll apply the effect to a simple image <strong>of</strong> a piece <strong>of</strong> paper.<br />

1. All we need is an image; add the following code to the <strong>of</strong> the template file:<br />

<br />

2. Next add the following simple script to the bottom <strong>of</strong> the page, in the empty<br />

function as with previous examples:<br />

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

$(this).effect("fold", { size: "50%" }, 1000);<br />

});<br />

3. Save this file as fold.html.<br />

[ 164 ]

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

Saved successfully!

Ooh no, something went wrong!