Simple JavaScript Animation

This is an example of moving an object on the screen. It makes use of the setTimeout method. In this case, it just moves the image so far to the right and moves back. You can set setTimeout's 2nd param (which is the length of time in ms), the number of pixels to move each iteration, and how far you want the image to move to the right.

One thing to note here, is how to increment the 'left' position of the image. These values are strings, so if you try to do smile_man.style.left + 1, this fails. You also need to put the unit of meausre, which in my case I used 'px'.

Time Out

Step Length

Goal line



smiley

Scripts