The simple color change we did in the previous example is some kind of animation, but we can do more. To produce a continuous movement or change of characteristics, normally achieved by a significant number of small successive changes, we use the setInterval method of the window object. This is how you use the method.
var intervalID = setInterval('someFunction()', 50);
In this example, someFunction is called repeatedly with an interval of 50 milliseconds. Note that the setInterval method returns a value that can be used to stop the animation. We stop animation by calling the clearInterval method on the window object.
Listing 8.2 provides an example of animation.