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.

Download from Wow! eBook <br />

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

flat.prev().css("z<strong>Index</strong>", "");<br />

flat.removeClass("flat").css("z<strong>Index</strong>", "");<br />

preFlat.addClass("flat");<br />

}<br />

} else {<br />

}<br />

};<br />

clearInterval(flatInterval);<br />

flat.css("z<strong>Index</strong>", order + 1);<br />

preMatrix[3] = -30 * oneRad;<br />

preMatrix[5] = -10 * oneRad;<br />

if(!flatInterval) {<br />

var flatInterval = setInterval(function() { skew() }, 1);<br />

}<br />

};<br />

What just happened?<br />

The first thing we do in our function is set the variables used by the function. We cache<br />

a reference to the current element that has the class flat and also set this element's<br />

z-index to be one higher than any <strong>of</strong> the other images to ensure it is always on top<br />

<strong>of</strong> the other images.<br />

We also cache a reference to the next image after the flat image. In this function, this will<br />

be the image to the right <strong>of</strong> the un-skewed image. We then make two copies <strong>of</strong> the original<br />

matrix array, one for the flat element and one for the preFlat element. To copy an array<br />

all we do is use JavaScript's slice() method with an index <strong>of</strong> zero.<br />

The next two variables we create are the initial dimensions <strong>of</strong> the flat and preFlat<br />

images. These variables are only used by IE, but because <strong>of</strong> hoisting we need to define<br />

them here and not in an IE-specific code block later in the function.<br />

Next we define an inline function called skew() which we'll repeatedly call in order to<br />

produce the actual animation. Within this function we first check that there is an element<br />

after the flat element by checking that the preFlat object has a length. If the length is<br />

equal to zero (that is if it does not have length), we simply clear any intervals that may exist,<br />

and make sure the flat element is at the top <strong>of</strong> the z-index stack.<br />

[ 256 ]

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

Saved successfully!

Ooh no, something went wrong!