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 />

Subjects that we'll look at in this chapter will include:<br />

The API<br />

Drawing to the <br />

Animating the <br />

Using with <strong>jQuery</strong><br />

in IE and the alternatives<br />

Creating a based game<br />

The canvas API<br />

The element comes with a rich scripting API that exposes methods and properties<br />

allowing us to define and control the shapes that are drawn on the canvas. The API can be<br />

broken down into distinct sections depending on what the methods do.<br />

The canvas element<br />

The element itself has a couple <strong>of</strong> methods that can be called on it, including:<br />

Method Usage<br />

getContext(a) Returns an object (a CanvasRenderingContext2D object to be precise) which<br />

can then have other methods from the API called on it to manipulate the<br />

. The argument specifies the type <strong>of</strong> context to retrieve. Only<br />

two dimensional contexts are available at present.<br />

toDataURL() Returns a data URL representing the image on the . Optional<br />

arguments include the type <strong>of</strong> image represented by the data URL (with the<br />

default being image/png), and any arguments specific to the type, such as<br />

the quality for image/jpg data URLs.<br />

The element can be thought <strong>of</strong> as being similar to an element that doesn't<br />

have an src attribute. Allowed attributes include the width and height <strong>of</strong> the element, an<br />

id and a class, among others. There are no special attributes associated with the canvas,<br />

although it can contain other elements. When the browser cannot display the ,<br />

it can display the element's content as a fallback. The only properties <strong>of</strong> the <br />

element we have access to, are the width and height. Setting either <strong>of</strong> these properties<br />

causes the to reset its contents to nothing, which can be useful when we want<br />

to clear it.<br />

[ 266 ]

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

Saved successfully!

Ooh no, something went wrong!