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

[ 139 ] Chapter 6 The download builder shown in the previous screenshot gives us everything we need to run any subset of the library components. All we'll be using in this chapter are the effects, so when we download a package we should only select the components found in the effects subsection at the left. We don't need to include a theme, and we don't even need to include the library core. The effects can be used completely independently of the rest of the library; all we need is the effects Core file and the individual effects we require. Make sure all of them are selected and download the package. The package will give us everything we need to use the components we've selected, including a copy of the latest stable release of jQuery, so when using jQuery UI, jQuery itself does not need to be downloaded separately. All of the JavaScript for each selected component is combined and compressed into a single file by the download builder, and any functional CSS or theme files will be combined into a single stylesheet. We don't need any of the theme files for working with the effects, but ensure the .js file from the archive provided by the download builder goes into our js folder. A new template file The examples in the remainder of this chapter will be short, mostly image-based examples that illustrate each effect in turn, so it makes sense to use a slightly different template file for them. Create a new template file by adding a reference to the jQuery UI source file directly after the jQuery one just before the closing tag. We won't be using any HTML5 elements in this chapter so we can safely remove the link to shiv.js in our new template file. The new effects added by jQuery UI jQuery UI gives us 14 new predefined animations to use in our pages; these are listed, together with a brief description of their usage, as follows: Animations Description blind The target element is shown or hidden by rolling it down or up like a window blind. bounce The target element is bounced horizontally or vertically for a specified number of times. clip The target element is shown or hidden by moving opposing edges in towards the center of the element, or out to its full width or height. drop The element appears to drop onto or off of the page in order to show or hide it respectively.

Extended Animations with jQuery UI Animations Description explode The explode effect causes the target element to separate into a specified number of pieces before fading away, or to fade into view in several pieces before coming together to form the complete element. fold The element appears to fold closed or open. highlight The background-color of the target element is set (to yellow by default, although this is configurable), and then fades away after a short interval. puff The target element increases in size slightly and then fades away. pulsate The target element's opacity is adjusted a specified number of times, making the element appear to flicker on and off. scale The dimensions of the target element are adjusted to increase or decrease its size. shake The target element is shaken a specified number of times. This effect is similar to the bounce effect with the key difference that the distance of the shake remains the same on each iteration of the animation. size The dimensions of the target element are adjusted to increase or decrease its size. This effect is almost identical to scale. slide The target element is made to slide in or out of view, horizontally or vertically. transfer The outline of the specified element is transferred to another element on the page. Using the effect API jQuery UI introduces the effect() method which can be used to trigger any of the effects listed in the previous table. The effect() method's usage pattern is as follows: jQuery(elements).effect(effect name, [configuration], [duration], [callback]); The name of the effect that we would like to use is always the first argument of the effect() method. It is supplied in string format. Each effect has custom configuration options that can be set to control how the effect displays. These options are set in a configuration object which is passed to the effect() method as the second argument, following the name of the effect. We can also supply a duration for the effect as an argument. As with standard jQuery animations, we can supply either an integer representing the duration of the effect in milliseconds, or one of the strings slow or fast. If no configuration is required, the duration may be passed to the effect() method as the second argument. If no duration is supplied, the default duration of 400 milliseconds will be used. [ 140 ]

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

<strong>Animation</strong>s Description<br />

explode The explode effect causes the target element to separate into a specified number<br />

<strong>of</strong> pieces before fading away, or to fade into view in several pieces before coming<br />

together to form the complete element.<br />

fold The element appears to fold closed or open.<br />

highlight The background-color <strong>of</strong> the target element is set (to yellow by default,<br />

although this is configurable), and then fades away after a short interval.<br />

puff The target element increases in size slightly and then fades away.<br />

pulsate The target element's opacity is adjusted a specified number <strong>of</strong> times, making the<br />

element appear to flicker on and <strong>of</strong>f.<br />

scale The dimensions <strong>of</strong> the target element are adjusted to increase or decrease its size.<br />

shake The target element is shaken a specified number <strong>of</strong> times. This effect is similar to<br />

the bounce effect with the key difference that the distance <strong>of</strong> the shake remains the<br />

same on each iteration <strong>of</strong> the animation.<br />

size The dimensions <strong>of</strong> the target element are adjusted to increase or decrease its size.<br />

This effect is almost identical to scale.<br />

slide The target element is made to slide in or out <strong>of</strong> view, horizontally or vertically.<br />

transfer The outline <strong>of</strong> the specified element is transferred to another element on the page.<br />

Using the effect API<br />

<strong>jQuery</strong> UI introduces the effect() method which can be used to trigger any <strong>of</strong> the effects<br />

listed in the previous table. The effect() method's usage pattern is as follows:<br />

<strong>jQuery</strong>(elements).effect(effect name, [configuration], [duration],<br />

[callback]);<br />

The name <strong>of</strong> the effect that we would like to use is always the first argument <strong>of</strong> the<br />

effect() method. It is supplied in string format.<br />

Each effect has custom configuration options that can be set to control how the effect<br />

displays. These options are set in a configuration object which is passed to the effect()<br />

method as the second argument, following the name <strong>of</strong> the effect.<br />

We can also supply a duration for the effect as an argument. As with standard <strong>jQuery</strong><br />

animations, we can supply either an integer representing the duration <strong>of</strong> the effect in<br />

milliseconds, or one <strong>of</strong> the strings slow or fast.<br />

If no configuration is required, the duration may be passed to the effect() method as<br />

the second argument. If no duration is supplied, the default duration <strong>of</strong> 400 milliseconds<br />

will be used.<br />

[ 140 ]

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

Saved successfully!

Ooh no, something went wrong!