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

Download from Wow! eBook The following screenshot shows an image in IE8 fading out correctly: We can see in the previous screenshot that there are no black borders around the image while it is fading out in IE8. In this example, I put the PNG into a container, set the background-color of the container to white, and faded out the container. [ 33 ] Chapter 2 Using fadeToggle() for convenient state-checking logic The fadeToggle() method exposed by jQuery will either fade an element in, or fade it out depending on the current state of the element. Elements that are visible will be faded out, while elements that are hidden will be faded in. When elements are faded out with fadeToggle(), they will automatically be set to display:none at the end of the animation so that the element doesn't affect the layout of the page.

Fading Animations Time for action – showing and hiding with fadeToggle() As before, we first create the HTML markup and CSS styling required by the example. 1. Open up a new copy of the template file and add the following code to the of the page: Enter your name: Your name. You know, the thing that people call you by 2. Save this page as fadeToggle.html. Next we need to add a few styles. In a new page in your text editor, add the following code: form { width:280px; margin:100px auto; position:relative; } input { margin-left:5px; } #help { display:block; width:16px; height:16px; margin-top:3px; float:right; cursor:pointer; background:url(../img/help.png) no-repeat; } #helpText { display:none; width:100px; height:75px; padding:12px 18px; position:absolute; left:115px; top:-90px; font:normal 12px "Nimbus Sans L", "Helvetica Neue", "Franklin Gothic Medium", Sans-serif; background:url(../img/bubble.png) no-repeat; } 3. Save this file as fadeToggle.css in the css folder. Finally, let's add the script that will make the example work. Within the anonymous function in the second element, add the following code: $("#help").click(function() { $("#helpText").fadeToggle(); }); What just happened? On the page we have a simple containing a label, an , and a couple of elements. The first is used as an icon, while the second contains help text to prompt the user for the value the expects. [ 34 ]

Download from Wow! eBook <br />

The following screenshot shows an image in IE8 fading out correctly:<br />

We can see in the previous screenshot that there are no black borders around the<br />

image while it is fading out in IE8. In this example, I put the PNG into a container, set the<br />

background-color <strong>of</strong> the container to white, and faded out the container.<br />

[ 33 ]<br />

Chapter 2<br />

Using fadeToggle() for convenient state-checking logic<br />

The fadeToggle() method exposed by <strong>jQuery</strong> will either fade an element in, or fade it out<br />

depending on the current state <strong>of</strong> the element. Elements that are visible will be faded out,<br />

while elements that are hidden will be faded in.<br />

When elements are faded out with fadeToggle(), they will automatically be set to<br />

display:none at the end <strong>of</strong> the animation so that the element doesn't affect the layout<br />

<strong>of</strong> the page.

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

Saved successfully!

Ooh no, something went wrong!