jQuery 1.4 Animation Techniques - Index of
jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of
[ 241 ] Chapter 9 Setting the auto expand parameter causes the image to increase in size, which is a slight inconvenience to say the least. However if we don't set this, the element will be clipped, as shown in the following screenshot: Clipping pretty much destroys our simple box (and the content is still scaled), as we can see in the previous screenshot. CSS3 3D transforms All of the transform functions we have looked at so far are two-dimensional, operating on just the x and y axes. Transforms that operate in three dimensions, along x, y, and z axes have also been proposed. 3D equivalents of all of the transform functions exist and usually just take an extra parameter which corresponds to the vector of each dimension, and the angle. For example, a 3D rotation could be added using this code: transform: rotate3d(0, 1, 0, 30deg); As with 2D transforms, there is an all-encompassing matrix function that allows us to implement any of the other transforms and allows us to combine some of them together on a single element.
CSS3 Animations If, like me, you thought the 2D transform matrix, with its six parameters, was complex and perhaps a little hard to understand, wait till you start using the 3D matrix, which has 16 parameters in total! At present 3D transforms are only supported in Webkit-based browsers, so we won't be looking at these in any further detail. But hopefully they'll be appearing in more browsers sooner rather than later. Animated rotation with jQuery and CSS3 In this example, we'll set up an animation that rotates an image using the rotate() transform function. Because this is supported by the majority of common browsers it's actually really easy to implement, and can be a great effect that enhances the appearance and behavior of the page it is used on. Time for action – animating an element's rotation We'll just be rotating a simple image in this example, so this is the only visible element we need in the of the page. 1. Add the following to a fresh copy of the template file: 2. At this point we don't even need any styles as everything we need to set can be done in the JavaScript, which we'll add next. 3. In the function at the bottom of the HTML page, add the following code: var img = $("#colorWheel"), offset = img.offset(), origWidth = img.width(), origHeight = img.height(), rotateStrings = [ "rotate(", 0, "deg)" ], getVendor = function() { var prefix = null, vendorStrings = { pure: "transform", [ 242 ]
- Page 211 and 212: Full Page Animations 2. The bgpos c
- Page 213 and 214: Full Page Animations nav ul { margi
- Page 215 and 216: Full Page Animations screensize = {
- Page 217 and 218: Full Page Animations What just happ
- Page 219 and 220: Full Page Animations The second sec
- Page 221 and 222: Full Page Animations Pop quiz - cre
- Page 223 and 224: Full Page Animations Time for actio
- Page 225 and 226: Full Page Animations Next we define
- Page 228 and 229: 8 Other Popular Animations This cha
- Page 230 and 231: [ 209 ] Chapter 8 } .slider #scroll
- Page 232 and 233: }), pointerText = "Use your pointer
- Page 234 and 235: [ 213 ] Chapter 8 In the previous s
- Page 236 and 237: prox.mousemove(function(ev) { goAni
- Page 238 and 239: Pop quiz - implementing proximity a
- Page 240 and 241: [ 219 ] Chapter 8 What just happene
- Page 242 and 243: 2. Save the new page as marquee.htm
- Page 244 and 245: [ 223 ] Chapter 8 1. jQuery provide
- Page 246 and 247: clear:both; } div#fadeLeft, div#fad
- Page 248 and 249: Time for action - animating the pos
- Page 250: 2. In this example we used the dele
- Page 253 and 254: CSS3 Animations The following trans
- Page 255 and 256: CSS3 Animations Units It is of crit
- Page 257 and 258: CSS3 Animations Skew Remember the t
- Page 259 and 260: CSS3 Animations Calculating the sin
- Page 261: CSS3 Animations The filter property
- Page 265 and 266: CSS3 Animations } el.filters.item("
- Page 267 and 268: CSS3 Animations An unfortunate prob
- Page 269 and 270: CSS3 Animations The context of this
- Page 271 and 272: CSS3 Animations Time for action - i
- Page 273 and 274: CSS3 Animations The first variable
- Page 275 and 276: CSS3 Animations Time for action - a
- Page 277 and 278: Download from Wow! eBook CSS3 Anim
- Page 279 and 280: CSS3 Animations We also have to upd
- Page 281 and 282: CSS3 Animations flatMatrix[3] = fla
- Page 283 and 284: CSS3 Animations When updating the s
- Page 285 and 286: CSS3 Animations translate translate
- Page 287 and 288: Canvas Animations Subjects that we'
- Page 289 and 290: Canvas Animations We can set the co
- Page 291 and 292: Download from Wow! eBook Canvas An
- Page 293 and 294: Canvas Animations All imageData obj
- Page 295 and 296: Canvas Animations context.beginPath
- Page 297 and 298: Canvas Animations For the next part
- Page 299 and 300: Canvas Animations Time for action -
- Page 301 and 302: Canvas Animations 3. Save the new p
- Page 303 and 304: Canvas Animations Time for action -
- Page 305 and 306: Canvas Animations Once the rectangl
- Page 307 and 308: Canvas Animations We then define tw
- Page 309 and 310: Canvas Animations }, context.lineTo
- Page 311 and 312: Canvas Animations Creating a canvas
CSS3 <strong>Animation</strong>s<br />
If, like me, you thought the 2D transform matrix, with its six parameters, was complex and<br />
perhaps a little hard to understand, wait till you start using the 3D matrix, which has 16<br />
parameters in total!<br />
At present 3D transforms are only supported in Webkit-based browsers, so we won't be<br />
looking at these in any further detail. But hopefully they'll be appearing in more browsers<br />
sooner rather than later.<br />
Animated rotation with <strong>jQuery</strong> and CSS3<br />
In this example, we'll set up an animation that rotates an image using the rotate()<br />
transform function. Because this is supported by the majority <strong>of</strong> common browsers it's<br />
actually really easy to implement, and can be a great effect that enhances the appearance<br />
and behavior <strong>of</strong> the page it is used on.<br />
Time for action – animating an element's rotation<br />
We'll just be rotating a simple image in this example, so this is the only visible element we<br />
need in the <strong>of</strong> the page.<br />
1. Add the following to a fresh copy <strong>of</strong> the template file:<br />
<br />
2. At this point we don't even need any styles as everything we need to set can be<br />
done in the JavaScript, which we'll add next.<br />
3. In the function at the bottom <strong>of</strong> the HTML page, add the following code:<br />
var img = $("#colorWheel"),<br />
<strong>of</strong>fset = img.<strong>of</strong>fset(),<br />
origWidth = img.width(),<br />
origHeight = img.height(),<br />
rotateStrings = [<br />
"rotate(",<br />
0,<br />
"deg)"<br />
],<br />
getVendor = function() {<br />
var prefix = null,<br />
vendorStrings = {<br />
pure: "transform",<br />
[ 242 ]