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

[ 161 ] Chapter 6 Gothic Medium", Sans-serif; } #confirmation p { margin:0; position:relative; top:18px; } 4. Save the CSS as drop.css. 5. When the page loads, the message should initially be displayed before fading away after a short interval: The previous screenshot shows the message slowly being hidden. It will appear to slide up and fade out at the same time when being hidden after the timer interval has passed. What just happened? The underlying markup of the message itself is extremely simple; we just need a container and the actual message. In our example the message is hardcoded into the page, but we could easily set this dynamically depending on the action being reported.

Extended Animations with jQuery UI The CSS is equally as simple, supplying a background color for the page to better highlight the message, and providing some basic styles for the container and the message itself. The most important rule (in this implementation) is that the container is initially hidden from view. Our script shows the message as soon as the page has loaded, but normally it would be triggered by the completion of some system action. We use the effect() method to initiate the effect and configure the mode to show and the direction to up (the element will still appear to drop downwards because it is positioned absolutely) using a configuration object passed as the second argument to the effect() method. Within the callback function passed to the effect method, we create an inline function stored in the timer variable. Within this function we just hide the confirmation message, using the effect() method and setting the mode configuration option to hide and the direction option to up once again. After this function definition we use JavaScript's setTimeout function to execute the timer function after three seconds have elapsed. We use a closure to call our timer function in keeping with the current best-practice. The explode effect The explode effect provides a great visual show by literally exploding the selected element into a specified number of pieces before fading them away. This effect can be used with both the effect API as well as show, hide, or toggle logic. Configuration options When using the explode effect we can control how many pieces the element is exploded into, and whether the element is shown or hidden: Option Default Usage mode "hide" Sets whether the element is shown or hidden when used with the effect() method. Other values are show, effect, and toggle. pieces 9 Sets the number of pieces the element is exploded into. [ 162 ]

[ 161 ]<br />

Chapter 6<br />

Gothic Medium", Sans-serif;<br />

}<br />

#confirmation p { margin:0; position:relative; top:18px; }<br />

4. Save the CSS as drop.css.<br />

5. When the page loads, the message should initially be displayed before fading away<br />

after a short interval:<br />

The previous screenshot shows the message slowly being hidden. It will appear to slide up<br />

and fade out at the same time when being hidden after the timer interval has passed.<br />

What just happened?<br />

The underlying markup <strong>of</strong> the message itself is extremely simple; we just need a container<br />

and the actual message. In our example the message is hardcoded into the page, but we<br />

could easily set this dynamically depending on the action being reported.

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

Saved successfully!

Ooh no, something went wrong!