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

[ 31 ] Chapter 2 For example, the application may generate a large number of dialogs during any single session and if the user has to repeatedly wait half a second every time they close a dialog, they may perceive that the animation is wasting their time or otherwise acting as a barrier to their interaction. I believe it is best to pass control of whether the animation is used or not back to the visitor, and provide an option to disable the animation if the system is going to be generating them on a regular basis. This way, users will be able to remove the effect if they do feel that it is a barrier. Pop quiz – using fadeOut 1. What happens if the integer 0 is supplied as the value of the duration argument? a. The animation occurs instantly b. The animation runs at the default speed of 400 milliseconds c. Animations with jQuery are disabled globally d. A script error is thrown 2. How can we access the element that was animated within a supplied callback function? a. The callback function is passed a reference to the element that was animated b. By reselecting it from the DOM c. Using the jQuery property animatedElement d. Using the this keyword (optionally wrapped in jQuery functionality ($(this)) Have a go hero – doing more with fadeout A popular implementation that makes use of fade-out animations is a "growl" style messaging system where feedback is provided in the form of messages that pop up in the viewport before fading away; why not create your own growl style messaging system that utilizes the fadeOut() method. Fading PNGs in IE In the previous examples, we've looked at fading in and out using CSS background colors to illustrate the effect. We could easily extend it to include background images instead, which generally work just as well, if not better, with this effect.

Fading Animations One thing to watch out for when using background images in conjunction with fading animations however is that problems can be encountered with the display of the images when the animations are viewed in Microsoft's Internet Explorer. It is known as the black-border problem and causes a black aura to be displayed around the image when a PNG with alpha-transparency (semi-opacity) is used as the background image. It really only affects IE8 as there are work-arounds that can be used to fix the issue in both IE7 and IE6. Here's a screenshot of the problem: The previous screenshot shows a fadeout() animation in progress. The jagged black border around the logo is the issue we face in IE and is caused by Microsoft's proprietary filter properties, which jQuery uses to set the opacity (and produce the fade) in IE. There are several different fixes for this issue including: Fading the container of the element instead of the element directly Giving the container, or the element that is faded, a background color Whichever solution works best will depend on the situation at hand. An alternative solution, but which only fixes the issue in both IE6 and IE7, involves using the DD_BelatedPng.js library, to display alpha-transparent PNGs using VML. Unfortunately this doesn't work in IE8, so sometimes a combination of fixes may be required. [ 32 ]

[ 31 ]<br />

Chapter 2<br />

For example, the application may generate a large number <strong>of</strong> dialogs during any single<br />

session and if the user has to repeatedly wait half a second every time they close a dialog,<br />

they may perceive that the animation is wasting their time or otherwise acting as a barrier<br />

to their interaction.<br />

I believe it is best to pass control <strong>of</strong> whether the animation is used or not back to the visitor,<br />

and provide an option to disable the animation if the system is going to be generating them<br />

on a regular basis. This way, users will be able to remove the effect if they do feel that it is<br />

a barrier.<br />

Pop quiz – using fadeOut<br />

1. What happens if the integer 0 is supplied as the value <strong>of</strong> the duration argument?<br />

a. The animation occurs instantly<br />

b. The animation runs at the default speed <strong>of</strong> 400 milliseconds<br />

c. <strong>Animation</strong>s with <strong>jQuery</strong> are disabled globally<br />

d. A script error is thrown<br />

2. How can we access the element that was animated within a supplied<br />

callback function?<br />

a. The callback function is passed a reference to the element that was animated<br />

b. By reselecting it from the DOM<br />

c. Using the <strong>jQuery</strong> property animatedElement<br />

d. Using the this keyword (optionally wrapped in <strong>jQuery</strong> functionality<br />

($(this))<br />

Have a go hero – doing more with fadeout<br />

A popular implementation that makes use <strong>of</strong> fade-out animations is a "growl" style<br />

messaging system where feedback is provided in the form <strong>of</strong> messages that pop up in the<br />

viewport before fading away; why not create your own growl style messaging system that<br />

utilizes the fadeOut() method.<br />

Fading PNGs in IE<br />

In the previous examples, we've looked at fading in and out using CSS background colors to<br />

illustrate the effect. We could easily extend it to include background images instead, which<br />

generally work just as well, if not better, with this effect.

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

Saved successfully!

Ooh no, something went wrong!