Next page | Contents page |

Time events

Time events don't work in quite the same way as mouse or key events. We do not add a listener function for them. Instead there are 3 predefined functions that we can call at any point in our program:

Typically you might call one of these at the end of your processing.

The first two return timer identifiers that may be used for cancelling the effect using clearTimeout(timerId) or clearInterval(timerId).

The third one, requestAnimationFrame, is best for repeated calls for making smooth animations. Display frequencies these days are 60Hz or higher. If 60Hz that means 16.67ms between frames. So it would be good if the processing functions take less time than that. Otherwise frames will be missed and the animation will become jerky (unless of course you can hit every second frame, or something like that).

So how long does our processing take? The next page shows how to find that out.

Next page | Contents page |