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.

Context methods<br />

There are two methods that relate directly to the context object returned by the<br />

getContext() method. These are:<br />

Method Usage<br />

[ 267 ]<br />

Chapter 10<br />

save() Saves the current state <strong>of</strong> the canvas; only transforms are saved, not shapes or<br />

paths.<br />

restore() Restores the saved state.<br />

We can also set a couple <strong>of</strong> global properties that apply to all shapes on the .<br />

These properties are:<br />

Property Usage<br />

globalAlpha Sets the alpha transparency <strong>of</strong> shapes. Takes a decimal<br />

between 0.0 and 1.0.<br />

globalCompositeOperation Sets how shapes stack up on top <strong>of</strong> one another. Can be used<br />

to create masks and clear areas <strong>of</strong> shapes.<br />

Native shapes<br />

The has just one native shape defined: the rectangle. One important point to note<br />

here is that the element does not have an internal DOM tree—shapes or paths<br />

we draw on the are not created as child elements <strong>of</strong> the element<br />

and cannot be accessed with standard DOM manipulation methods. They are not individual<br />

objects, they are just pixels. Methods from the scripting API used specifically when working<br />

with rectangles include the following:<br />

Method Usage<br />

clearRect(a, b, c, d) Removes all shapes and paths from an area <strong>of</strong> the canvas.<br />

Arguments a and b specify the coordinates to begin clearing at<br />

and arguments c and d specify the width and height <strong>of</strong> the area to<br />

clear.<br />

fillRect(a, b, c, d) Draws a rectangle. Arguments a and b specify the coordinates to<br />

begin drawing at and arguments c and d specify the width and<br />

height <strong>of</strong> its sides.<br />

strokeRect(a, b, c, d) Draws the outline <strong>of</strong> a rectangle. Arguments a and b represent the<br />

starting coordinates <strong>of</strong> the shape and arguments c and d represent<br />

the width and height <strong>of</strong> its sides.

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

Saved successfully!

Ooh no, something went wrong!