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.

[ 259 ]<br />

Chapter 9<br />

At this point the flat image has been skewed to the left, resized and translated, and the<br />

preFlat image has been skewed back to zero, resized and translated. Both the flat and<br />

preFlat images are transformed together at the same time, which is why the function is<br />

as large as it is.<br />

Right at the end <strong>of</strong> the skewRTL() function, defined after the skew() function that will be<br />

repeatedly called by the setInterval() function, we initialize the 3rd and 5th values in<br />

the preMatrix array so that the array will contain the correct skew for the initial state <strong>of</strong><br />

the element. When we create the array, by copying the original matrix array used when the<br />

widget is initialized, these items will both be set to 0.<br />

Before calling the setInterval() function on the two images to be skewed, we first<br />

check that an interval doesn't already exist. This stops the widget from breaking if the link<br />

is repeatedly clicked by the visitor. The element will be skewed more than once if the link is<br />

clicked several times in rapid succession, but the widget will continue to function and the<br />

page will not throw errors.<br />

Time for action – skewing an element from left to right<br />

We can now add the function that skews an element from left to flat and from flat to right.<br />

This function is very similar to the function we just looked at. Changes in the code are shown<br />

in bold:<br />

function skewLTR() {<br />

var flat = flow.find(".flat"),<br />

preFlat = flat.prev(),<br />

flatMatrix = matrix.slice(0),<br />

preMatrix = matrix.slice(0),<br />

flatDims = 200,<br />

preDims = 170,<br />

skew = function() {<br />

if (preFlat.length) {<br />

if (flatMatrix[3] >= -30 * oneRad && flatMatrix[5] >=<br />

-10 * oneRad) {<br />

var preTranslateX = parseInt(preMatrix[9].<br />

split("p")[0], 10),<br />

preTranslateY = parseInt(preMatrix[10].<br />

split("p")[0], 10);<br />

flatMatrix[1] = flatMatrix[1] - 0.001;

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

Saved successfully!

Ooh no, something went wrong!