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.

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

We also have to update the preFlat image so that it goes from being skewed to the right to<br />

being flat. We also have to increase the size <strong>of</strong> the preFlat image as they start out smaller.<br />

In a similar way to before, we update the relevant array items in the preMatrix so that<br />

over the course <strong>of</strong> 30 iterations <strong>of</strong> the skew() function they end up at the right values.<br />

The preFlat image also needs to be translated, but this time along both the x and y axes.<br />

Next we check the vendor string once more and as long as it isn't filter (IE), we apply the<br />

transform to the flat and preFlat image by joining the array. If it is IE we have to do a<br />

little more work to apply the transformation.<br />

We apply each <strong>of</strong> the relevant Matrix properties, M12 and M21 on the flat and preFlat<br />

images. We use <strong>jQuery</strong>'s get() method with an index <strong>of</strong> 0 to obtain the actual DOM<br />

element once more. We also reduce the size <strong>of</strong> the flat image, and increase the size <strong>of</strong> the<br />

preFlat image using our flatDims and preDims variables that we initialized earlier and<br />

then <strong>jQuery</strong>'s css() method to apply the new sizes.<br />

IE's Matrix property helpfully ignores the scaling parameters when the sizingMethod is<br />

set to auto expand, but this property must be set to prevent the images from being clipped.<br />

This is why we fallback to <strong>jQuery</strong>'s css() method.<br />

Unusually, we are able to set fractional pixel sizes when using IE, which is fortunate as it<br />

allows us to set the size <strong>of</strong> the images correctly in order for them to end up at the right size<br />

when the animation ends.<br />

We now come to the other part <strong>of</strong> the inner conditional. This block <strong>of</strong> code is executed once<br />

at the end <strong>of</strong> the animation when the third and fifth items in our flatMatrix array are<br />

greater than 30 and 10 respectively.<br />

First we clear the intervals so that the skew is not animated further. We then check the<br />

vendor string once more, and as long as it isn't filter we reset the skew on the flat<br />

element to 0 (on both the x and y axes).<br />

This is needed because for some reason, the preFlat image doesn't quite go back to exactly<br />

zero. I assume this is because JavaScript's Math functions do not allow the number to have<br />

enough decimal places to be entirely accurate. The image is only slightly <strong>of</strong>f however, so this<br />

sudden switch to 0 at the end <strong>of</strong> the animation is not noticeable.<br />

Unfortunately, translating an element at the same time as skewing it does not seem possible<br />

in IE. What happens is that IE applies the new skew, but fails to apply the new position until<br />

after the skew animation has finished, so the element is skewed and then moved in two<br />

separate steps. It doesn't look too great so instead we simply reposition the flat element<br />

without animating it at this point once the skew animation has finished.<br />

After correcting the skew, or the position, we then remove the z-index from the flat<br />

element (which has now been skewed to the left) and remove the class name flat from it,<br />

and then add the class name flat to the preFlat element.<br />

[ 258 ]

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

Saved successfully!

Ooh no, something went wrong!