04.07.2013 Views

Building Web Applications with SVG - Cdn.oreilly.com

Building Web Applications with SVG - Cdn.oreilly.com

Building Web Applications with SVG - Cdn.oreilly.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Here’s how it’s done:<br />

■■ The animation All animation is handled declaratively (using SMIL). That is, there are no<br />

JavaScript statements involving setTimeout() or setInterval() (used for conventional web<br />

animation). A generic animation that handles the rotation of the clock’s hands is declared in<br />

markup and then cloned through JavaScript, <strong>with</strong> its properties being modified in a simple<br />

loop that handles the details of how fast each hand should move. Likewise, the gears are each<br />

cloned from one protogear, <strong>with</strong> the dash patterns around their edges and their rotations<br />

being assigned different speeds.<br />

■■ The markup The markup is kept minimal by using script to replicate many copies of similar<br />

things. <strong>SVG</strong> does not yet have a element that might allow some of this script to<br />

be handled declaratively. In the meantime, we can use markup and script for what each does<br />

best—<strong>SVG</strong> allows the pleasant intermingling of both. The JavaScript is also used to assign<br />

colors, sizes, and speeds to the various gears, and to determine the actual time of day so the<br />

clock’s hands may be initialized.<br />

■<br />

■ The clock face The hour marks are also done declaratively by setting the dash-array attribute<br />

of the stroke around the clock face. The appearance of a slight curvature to the clock<br />

face is provided through a radial gradient.<br />

CHAPTER 1 <strong>SVG</strong> Basics 15

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

Saved successfully!

Ooh no, something went wrong!