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.

[ 245 ]<br />

Chapter 9<br />

If none <strong>of</strong> these tests identify a vendor prefix, then it's likely that the browser in use is a<br />

version <strong>of</strong> Internet Explorer. Internet Explorer versions 8 and below do not currently have a<br />

vendor prefix (although IE9 does feature one) and do not support the rotate function at all.<br />

It does support rotation via its proprietary filter property however.<br />

If the vendor variable is still set to null at this point, we set the variable to filter. In order<br />

to programmatically work with the value <strong>of</strong> the filter property in IE, the filter must<br />

already be applied to the element, so we also set a filter on the element in this part <strong>of</strong> the<br />

code using <strong>jQuery</strong>'s css() method ready for us to manipulate later in the code. We also set<br />

the sizing mode to auto expand in order to prevent the element from being clipped when<br />

the rotate is applied.<br />

At the end <strong>of</strong> the function the prefix variable is returned containing a string <strong>of</strong> the vendor<br />

prefix for the browser currently in use. Directly after the function we set a variable called<br />

vendor which will contain the value returned by the function for easy reference.<br />

Next we define a regular function doRotate() which will be used to perform the actual<br />

rotation. The first thing we do in this function is increment the second property <strong>of</strong> our<br />

rotateStrings array by one.<br />

We then check whether the vendor variable equals filter. If it does, we know that the<br />

browser in use is IE and can proceed to determine the values that the proprietary filter<br />

will need. IE allows rotation to be implemented in two different ways. We could use the<br />

BasicImage filter property to rotate the image, although that only allows us to set one<br />

<strong>of</strong> four rotation values: 0, 1, 2 or 3, which correspond to 0, 90, 180, or 270 degrees. This is<br />

simply not flexible enough for our needs in this example.<br />

So instead we use the Matrix filter, which gives us much more control over the degree <strong>of</strong><br />

rotation. This is very similar to the CSS3 matrix transform, with six parameter values that are<br />

combined to generate the different transforms (a rotation in this case).<br />

The parameters that we use in this example are M11, M12, M21, and M22 which map roughly<br />

to the first four values in the CSS3 version, with the exception that values two and three are<br />

reversed in Micros<strong>of</strong>t's version.<br />

The values <strong>of</strong> each <strong>of</strong> these properties must be computed using the JavaScript trigonometry<br />

Math.cos and Math.sin functions. We set some variables to calculate these values. The<br />

first, rad, converts the number <strong>of</strong> degrees <strong>of</strong> rotation into radians as these are the units<br />

required by the Matrix filter. The radians are calculated by multiplying the current degree<br />

<strong>of</strong> rotation (as stored in the second item in our rotateStrings array) by PI times 2 divided<br />

by 360.

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

Saved successfully!

Ooh no, something went wrong!