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.

Canvas <strong>Animation</strong>s<br />

3. Save the new page and view it in IE. Our flag should now be visible:<br />

IE can be made to understand the element, as we see in the previous screenshot,<br />

although its support is not completely identical to that <strong>of</strong> capable browsers. If we compare<br />

our example in IE and Firefox alongside each other, we see that IE also slightly enlarges the<br />

flag for some reason.<br />

What just happened?<br />

First <strong>of</strong> all we need to link to the explorercanvas library. We don't want to let normal<br />

browsers that support the native element use this file as it will slow them down,<br />

so we put the element into an IE-specific conditional comment (like we did with<br />

the html5shiv file earlier in the book). The .compiled version <strong>of</strong> the script file is simply a<br />

minified version for production use.<br />

The next change we make is to put the methods that draw the flag into an inline function<br />

stored as a variable. This is necessary because otherwise IE will attempt to use these drawing<br />

methods before the explorercanvas library has finished initializing and will throw errors.<br />

The next part <strong>of</strong> our code also deals with this.<br />

We use a conditional if statement to check for the presence <strong>of</strong> an ActiveXObject<br />

property <strong>of</strong> the window object (this will only exist in IE). If it is found, we attach an onload<br />

handler to the <strong>of</strong> the page that calls the getContext() method and our draw()<br />

function once the page has finished loading, and the explorercanvas library has done<br />

its thing.<br />

[ 280 ]

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

Saved successfully!

Ooh no, something went wrong!