O'Reilly logo

Sams Teach Yourself JavaScript™ in 24 Hours, Fifth Edition by Phil Ballard, Michael Moncur

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required