jQuery 1.4 Animation Techniques - Index of
jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of
[ 281 ] Chapter 10 If the browser is not IE, we simply get the context and call our draw() function straight away. Note that we pass the context object into the draw() function as an argument so that the API methods work correctly. Other than these changes, our code is the same and should now function as intended in IE versions 8 and below. Pop Quiz – supporting IE 1. We wrap the getContext() method in a conditional comment that checks for IE and uses an onload handler attached to the . Why? a. The can only be interacted with via the element in IE b. To give explorercanvas a chance to add getContext() support to the in IE c. To prevent memory leaks in IE d. A handler function must be used with explorercanvas 2. Which methods/techniques do now work in IE when using explorercanvas? a. Scaling and Bezier curves b. Radial gradients and quadratic curves c. Radial gradients, clearRect(), and non-uniform scaling d. Non-uniform scaling, PNG-based images, and stroked text Have a go hero – extending IE support Convert your own flag (or logo/alternative) so that it works in IE using the explorercanvas library. You'll more than likely need to make use of an onload event handler to ensure that the getContext() method isn't called until the is ready to be used. Animating the canvas The methods we've looked at so far are easy to use and nothing if not a little repetitive. Animating the objects on the is where things start to get interesting. Animating is harder than simply drawing on the and as we have no real way of debugging it other than trial and error, solving bugs can quickly become problematic and somewhat time-consuming. In our flag example, there was no real benefit to using the . We could have got exactly the same effect, with much less code and processing, by simply including an image of the flag on our page. However, animating the is where its benefits really begin. This is where we can do much more than anything we could achieve with a simple image. The additional complexity that animating the entails is totally worth it.
Canvas Animations Time for action – creating an animation on the canvas In this example, we'll draw the same flag as we did before, except that this time we'll animate the different shapes. The underlying HTML used in this example is exactly the same as in the previous examples. All that changes is the contents of the element at the end of the . 1. To make the working file for this example, just remove everything in the element at the bottom of canvas-explorer.html and resave the file as canvas-animated.html. 2. The first thing we'll do is bring the blue rectangle in from the side of the canvas to the center of the element. Add the following code to the now empty element at the bottom of the page: (function() { var canvas = document.getElementById("c"), init = function(context) { }; var width = 0, pos = 0, rectMotion = function() { if (width < 400) { width = width + 2; context.fillStyle = "#039"; context.fillRect(0, 50, width, 200); } else if (pos < 50) { pos = pos + 2; canvas.width = 500; context.fillStyle = "#039"; context.fillRect(pos, 50, 400, 200); } else { clearInterval(rectInt); whiteLines(context); } }, rectInt = setInterval(function() { rectMotion() }, 1); if (window.ActiveXObject) { window.onload = function() { [ 282 ]
- 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 and 262: CSS3 Animations The filter property
- Page 263 and 264: CSS3 Animations If, like me, you th
- 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: Canvas Animations 3. Save the new p
- 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
- Page 313 and 314: Canvas Animations Time for action -
- Page 315 and 316: Canvas Animations What just happene
- Page 317 and 318: Canvas Animations What just happene
- Page 319 and 320: Canvas Animations aliens.splice(x,
- Page 321 and 322: Canvas Animations Pop quiz - creati
- Page 323 and 324: Download from Wow! eBook
- Page 325 and 326: Pop Quiz Answers Using fadeToggle()
- Page 327 and 328: Pop Quiz Answers Using slideToggle
- Page 329 and 330: Pop Quiz Answers Implementing the p
- Page 331 and 332: Pop Quiz Answers Animating the canv
- Page 333 and 334: show() or hide() method, triggering
- Page 335 and 336: cssHooks using 239 cssHooks feature
- Page 337 and 338: fading animations 20 flicker effect
- Page 339 and 340: proximity animations about 207 exte
- Page 341 and 342: scaleY 232 skew 232 skewX 232 skewY
- Page 343 and 344: jQuery 1.4 Reference Guide ISBN: 97
[ 281 ]<br />
Chapter 10<br />
If the browser is not IE, we simply get the context and call our draw() function straight<br />
away. Note that we pass the context object into the draw() function as an argument so that<br />
the API methods work correctly. Other than these changes, our code is the same and should<br />
now function as intended in IE versions 8 and below.<br />
Pop Quiz – supporting IE<br />
1. We wrap the getContext() method in a conditional comment that checks for IE<br />
and uses an onload handler attached to the . Why?<br />
a. The can only be interacted with via the element in IE<br />
b. To give explorercanvas a chance to add getContext() support to the<br />
in IE<br />
c. To prevent memory leaks in IE<br />
d. A handler function must be used with explorercanvas<br />
2. Which methods/techniques do now work in IE when using explorercanvas?<br />
a. Scaling and Bezier curves<br />
b. Radial gradients and quadratic curves<br />
c. Radial gradients, clearRect(), and non-uniform scaling<br />
d. Non-uniform scaling, PNG-based images, and stroked text<br />
Have a go hero – extending IE support<br />
Convert your own flag (or logo/alternative) so that it works in IE using the explorercanvas<br />
library. You'll more than likely need to make use <strong>of</strong> an onload event handler to ensure that<br />
the getContext() method isn't called until the is ready to be used.<br />
Animating the canvas<br />
The methods we've looked at so far are easy to use and nothing if not a little<br />
repetitive. Animating the objects on the is where things start to get interesting.<br />
Animating is harder than simply drawing on the and as we have no real way <strong>of</strong><br />
debugging it other than trial and error, solving bugs can quickly become problematic and<br />
somewhat time-consuming.<br />
In our flag example, there was no real benefit to using the . We could have got<br />
exactly the same effect, with much less code and processing, by simply including an image<br />
<strong>of</strong> the flag on our page. However, animating the is where its benefits really begin.<br />
This is where we can do much more than anything we could achieve with a simple image.<br />
The additional complexity that animating the entails is totally worth it.