jQuery 1.4 Animation Techniques - Index of

jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of

02.06.2013 Views

9 CSS3 Animations CSS3 brings many impressive new styles to the web-development arena, and even though the specification is far from complete, many aspects of it are being used in the latest browsers. Pure-CSS animation may even make it into the specification at some point, and although at the time of writing few browsers support this, with a little help from jQuery we can create our own CSS3 animations that work with varying degrees of success, across most common browsers. In this chapter, we'll be covering the following topics: The different CSS3 transforms available Animating an element's rotation Using the CSS3 transforms matrix Animating an element's skew with jQuery For further information on CSS3 2D transforms, see the W3C Working Draft specification at http://www.w3.org/TR/css3-2d-transforms/. CSS3 2D transforms CSS3 defines a style property called transform which allows us to transform targeted elements in a two-dimensional space along x and y axes. A range of transform functions can be supplied as the value of the transform property, which dictates how the transformation should be applied.

CSS3 Animations The following transform functions are defined: Function Example usage Description of the transform matrix matrix(a, b, c, d, e, f) Rotates, scales, skews, or translates the element according to the combination of supplied parameters. rotate rotate(x) Rotates the element the specified number of degrees around the transform-origin. By default, the origin should be the center of the element. scale scale(x, y) Scales the element the specified number of units along the x and y axes. If y is not supplied, it is assumed to be the same as x. scaleX scale(x) Scales the element the specified number of units along the x axis. scaleY scale(y) Scales the element the specified number of units along the y axis. skew skew(x, y) Skews the element the specified number of degrees along the x and y axes. If y is not supplied it is assumed to be 0. skewX skew(x) Skews the element the specified number of degrees along the x axis. skewY skew(y) Skews the element the specified number of degrees along the y axis. translate translate(x, y) Repositions the element the specified number of pixels along the x and y axes. If y is not provided it is assumed to be 0. translateX translate(x) Repositions the element the specified number of pixels along the x axis. translateY translate(y) Repositions the element the specified number of pixels along the y axis. Understanding the matrix All of the individual transform functions (rotate(), skew(), among others) can be thought of as shortcuts for specific matrix transforms. Indeed, most browsers will apply a matrix behind-the-scenes even when a transform function is provided. The matrix takes six parameters, and each of the above transforms can be performed by providing different combinations of values for these parameters. Sometimes we can apply several transforms simultaneously by using the matrix. Let's look at some quick examples to illustrate how the matrix can be used. [ 232 ]

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

The following transform functions are defined:<br />

Function Example usage Description <strong>of</strong> the transform<br />

matrix matrix(a, b, c, d, e, f) Rotates, scales, skews, or translates the element<br />

according to the combination <strong>of</strong> supplied<br />

parameters.<br />

rotate rotate(x) Rotates the element the specified number <strong>of</strong><br />

degrees around the transform-origin. By default,<br />

the origin should be the center <strong>of</strong> the element.<br />

scale scale(x, y) Scales the element the specified number <strong>of</strong> units<br />

along the x and y axes. If y is not supplied, it is<br />

assumed to be the same as x.<br />

scaleX scale(x) Scales the element the specified number <strong>of</strong> units<br />

along the x axis.<br />

scaleY scale(y) Scales the element the specified number <strong>of</strong> units<br />

along the y axis.<br />

skew skew(x, y) Skews the element the specified number <strong>of</strong><br />

degrees along the x and y axes. If y is not supplied<br />

it is assumed to be 0.<br />

skewX skew(x) Skews the element the specified number <strong>of</strong><br />

degrees along the x axis.<br />

skewY skew(y) Skews the element the specified number <strong>of</strong><br />

degrees along the y axis.<br />

translate translate(x, y) Repositions the element the specified number <strong>of</strong><br />

pixels along the x and y axes. If y is not provided it<br />

is assumed to be 0.<br />

translateX translate(x) Repositions the element the specified number <strong>of</strong><br />

pixels along the x axis.<br />

translateY translate(y) Repositions the element the specified number <strong>of</strong><br />

pixels along the y axis.<br />

Understanding the matrix<br />

All <strong>of</strong> the individual transform functions (rotate(), skew(), among others) can be thought<br />

<strong>of</strong> as shortcuts for specific matrix transforms. Indeed, most browsers will apply a matrix<br />

behind-the-scenes even when a transform function is provided.<br />

The matrix takes six parameters, and each <strong>of</strong> the above transforms can be performed by<br />

providing different combinations <strong>of</strong> values for these parameters. Sometimes we can apply<br />

several transforms simultaneously by using the matrix. Let's look at some quick examples<br />

to illustrate how the matrix can be used.<br />

[ 232 ]

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

Saved successfully!

Ooh no, something went wrong!