Hour 15. Graphics and Animation

What You’ll Learn in This Hour

• How to preload images

• Using the setTimeout() and setInterval() methods

• Animating opacity

• Scripting DOM positioning

• Optimizing performance

Since the earliest days of JavaScript, one of its most frequent uses has been to add interest to pages by using graphics effects and animation. In this hour you learn how to do it.

Preloading Images

Various examples earlier in the book have carried out changes to images on the page by changing the value of the image’s src attribute.

When src is given a new value, if the browser doesn’t already have the newly requested image file in its cache it attempts to download it.

In many instances this works fine, especially for small images on ...

Get Sams Teach Yourself JavaScript™ in 24 Hours, Fifth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.