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 />

When updating the skew on our flat and preFlat elements, we are skewing the element<br />

the opposite way. To skew an element to the right, we need to use a minus figure so instead<br />

<strong>of</strong> going from 0 to 30 or from -30 to 0, we are going the opposite way, from 30 to 0 or 0 to<br />

-30, so we minus the radian equivalent <strong>of</strong> 1 degree instead <strong>of</strong> adding it.<br />

We are also translating to the right instead <strong>of</strong> to the left, so instead <strong>of</strong> removing 3 pixels each<br />

time to move the image left we add 3 pixels to move it right. We also provide different values<br />

for the dimensions variables used by IE.<br />

This time when we set the z-index <strong>of</strong> the element that was previously flat, we add 1 to<br />

the z-index <strong>of</strong> the next element (to the right) to make sure it is higher than this element.<br />

However, we can't use our length variable from earlier or it will be at the same z-index as<br />

the flat element, but will appear above it as it comes after the element in the DOM.<br />

The final difference is that when we initialize the third and fifth items in our array, we are<br />

specifying the current skew to the left and not the right, so these items are set to the radian<br />

equivalent <strong>of</strong> 30 and 10 degrees instead <strong>of</strong> -30 and -10.<br />

Time for action – wiring up the controls<br />

All that's left to do is add the event handlers to the left and right links at the bottom <strong>of</strong> the<br />

widget so that the different images can be viewed. After the two skew functions, add the<br />

following code:<br />

viewer.find("#left a").click(function(e) {<br />

e.preventDefault();<br />

skewRTL();<br />

});<br />

viewer.find("#right a").click(function(e) {<br />

e.preventDefault();<br />

skewLTR();<br />

});<br />

What just happened?<br />

All we do is add a click handler to each link which prevents the link from being followed<br />

with preventDefault() and then call the relevant skew function. The example should<br />

now be fully working in all common browsers, although the effect is handled rather badly<br />

by IE in general, with slower, more sluggish animations, less accurate skewing, and jittery,<br />

uncontrollable movements.<br />

One point to note is that there is a difference between the full and minified versions <strong>of</strong> the<br />

<strong>jQuery</strong> source file which causes IE to throw errors when the minified version is used, but not<br />

when the un-minified version is used.<br />

[ 262 ]

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

Saved successfully!

Ooh no, something went wrong!