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.

[ 253 ]<br />

Chapter 9<br />

This will allow us to select each element in turn one after the other on each iteration <strong>of</strong><br />

the loop. The first thing we do in the function is cache a reference to the current <br />

using the index as an argument for the eq() method. We add 1 to the index value to avoid<br />

selecting the first image.<br />

In the next block <strong>of</strong> code we set some <strong>of</strong> the items in our matrix array. We set the scale<br />

parameters (items 1 and 7 in the array) to 0.7 so that the skewed images are reduced in size<br />

slightly, and we set the skew parameters (items 3 and 5) to the radian equivalent <strong>of</strong> -30 and<br />

-10 degrees. This will skew the images slightly up and to the right.<br />

We also set the translate parameters (items 9 and 10 in the array) to position the skewed<br />

elements correctly so that they stack up horizontally. If the browser in use is Firefox we have<br />

to use px in the value for the translate properties, but with other browsers the values should<br />

be unit-less. We use a ternary condition to check the vendor variable (this will contain the<br />

vendor-prefix for the current browser) and set the value accordingly.<br />

Once we've set our array items we then check that the browser in use is not IE and provided<br />

it isn't, we apply the skew to the current element. We also set the z-index <strong>of</strong> the current<br />

element using the order variable, which is set to the length <strong>of</strong> the number <strong>of</strong> images.<br />

On each iteration <strong>of</strong> the loop we reduce the value <strong>of</strong> this variable by one (later in this section<br />

<strong>of</strong> code you'll see the statement index-- which decreases the variable). The z-index <strong>of</strong><br />

each element will therefore get progressively lower as we process each image.<br />

If the browser in use is IE, we apply the Micros<strong>of</strong>t matrix and set some different CSS on the<br />

images. The translate parameters don't work in IE, so we position the images using <strong>jQuery</strong><br />

instead. Skewing the elements in IE also causes the elements to increase in size, so we have<br />

to drastically reduce their dimensions, which we also do with <strong>jQuery</strong>.<br />

Once we have set the required CSS styles, we then skew the elements by manipulating the<br />

proprietary Micros<strong>of</strong>t matrix filters. Remember, these properties can only be manipulated<br />

on actual DOM elements, not <strong>jQuery</strong> objects, so we retrieve the raw element using <strong>jQuery</strong>'s<br />

get() method and the index 0.<br />

After the each() loop has finished, we reset parameters 3 and 5 in the matrix array. This<br />

is because we will use the array again several times, so each time we should use the default<br />

values for the parameters.

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

Saved successfully!

Ooh no, something went wrong!