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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.