02.06.2013 Views

jQuery 1.4 Animation Techniques - Index of

jQuery 1.4 Animation Techniques - Index of

jQuery 1.4 Animation Techniques - Index of

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

[ 25 ]<br />

Chapter 2<br />

Most <strong>of</strong> the styles we used in this example are purely for the layout and appearance <strong>of</strong> this<br />

example and can be changed to suit your implementational requirements. What's important<br />

is that the hover states for the navigation links are provided using the class name pure-css<br />

attached to the outer element.<br />

We do use a CSS3 style in this example, which some readers may not be familiar with. We'll<br />

be looking at CSS3 in much more detail towards the end <strong>of</strong> the book but, we'll cover this one<br />

for the benefit <strong>of</strong> those that have not used it before.<br />

The CSS3 style we used was the border-radius style, which gives the element rounded<br />

corners in supporting browsers. Few browsers currently support the true border-radius<br />

CSS3 style property (at the time <strong>of</strong> writing, only Opera supports this style property natively),<br />

but Firefox and Webkit-based browsers do support it with their vendor-prefixes, -moz- and<br />

–webkit- respectively.<br />

Internet Explorer 8 and below do not support the border-radius style property, or any<br />

variant <strong>of</strong> it, and these browsers do not provide their own vendor-prefixes to use. However,<br />

the menu itself and the example code, still work perfectly in these browsers. The only<br />

difference is, they have square corners and not rounded ones.<br />

If this is acceptable, then everything is fine, and you have super-simple rounded corners<br />

without the additional HTTP request(s) and payload that images would require in supporting<br />

browsers. If rounded corners are critical to your application or interface, we can always<br />

provide these to IE using conditional comments.<br />

Time for action – scripting the animation<br />

Now we just need to add the script that will animate our simple navigation menu.<br />

1. Add the following code within the anonymous function at the bottom <strong>of</strong><br />

the :<br />

var ul = $("nav ul");<br />

ul.removeClass("purecss");<br />

ul.find("a").each(function(){<br />

var a = $(this);<br />

a.append("" + a.text() + "");<br />

});<br />

ul.find("a").hover(function() {<br />

$(this).find("span").fadeIn("slow");<br />

}, function() {<br />

$(this).find("span").hide();<br />

});

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

Saved successfully!

Ooh no, something went wrong!