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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CSS3 <strong>Animation</strong>s<br />

The first variable we create is a cached selector for the outer container <strong>of</strong> our widget. This<br />

is the one and only <strong>jQuery</strong> object we create in this entire example. Some <strong>of</strong> the code we'll<br />

add is quite intensive in places, so keeping the number <strong>of</strong> <strong>jQuery</strong> objects we create to a bare<br />

minimum is essential for performance reasons.<br />

Next we use the original <strong>jQuery</strong> object and the find() <strong>jQuery</strong> method to cache a selector<br />

for the flow element (the direct parent <strong>of</strong> the image elements that will be skewed) as we'll<br />

need to access or manipulate this element several times as well.<br />

Then we store the number <strong>of</strong> image elements in the widget using the length property<br />

<strong>of</strong> a <strong>jQuery</strong> object containing the child elements <strong>of</strong> the flow element. We also store the<br />

result <strong>of</strong> converting one degree to one radian so that we can easily convert from one unit<br />

to another throughout the script without repeatedly performing the same calculation. Both<br />

the CSS3 transform matrix and IE's matrix filter can accept radians so that makes them a<br />

convenient unit to work with.<br />

We then create our matrix array, and Micros<strong>of</strong>t's matrix property as a string. The array<br />

includes all <strong>of</strong> the individual properties as array items, including the required commas as<br />

strings. The reason we include the commas in our array is so that we can call the join()<br />

JavaScript function on the array later without specifying a separator and without having to<br />

worry about removing the unnecessary commas this would insert incorrectly.<br />

Next we add the getVendor() function that we used in the last example. This is a<br />

convenient way to ensure the correct prefix is used when we apply the skew styling.<br />

We won't cover this function in detail as we have already looked at it earlier in the chapter.<br />

Again we call the function straight away after defining it and store the result in a variable<br />

for later use.<br />

The last variable we create will hold a string containing either the CSS3 matrix function with<br />

all required parameters, or it will contain IE's matrix property in its most basic form, with<br />

only the sizingMethod parameter defined. If you remember from the previous example,<br />

IE can only manipulate the matrix property after it has been initially set.<br />

At this point we can move on to prepare the first image. We select the first image using<br />

<strong>jQuery</strong>'s eq() method, passing in 0 as the index <strong>of</strong> the element we are interested in.<br />

We set a class name <strong>of</strong> flat on the first image so that we can easily select it later, and<br />

also give it a higher z-index than the other images so that it is visible in its entirety.<br />

Next we loop through the remaining images using <strong>jQuery</strong>'s each() method.<br />

The anonymous function we pass to the method accepts the parameter i which<br />

is the index <strong>of</strong> the current iteration.<br />

[ 252 ]

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

Saved successfully!

Ooh no, something went wrong!