O'Reilly logo

The Book of JavaScript, 2nd Edition by thau!

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

Repeating Timed Actions

You've already seen examples of repeating timed actions. The tip box discussed in the section "How the Book of JavaScript Tip Box Works" on page 136 displays each tip for 3.5 seconds, and the text box that tells you how long you've been on the page updates every second. Both of these examples use the same mechanism.

As you have just seen in Chapter 8, the usual way to get JavaScript to perform an action repeatedly is to put the action into a loop. Unfortunately, we can't use a while or for loop for repeated timed events. The while and for loops run too quickly, and there's no good way to slow them down. Even if you could slow them, there's no way to time these loops accurately, because they run at different speeds on different ...

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