View Full Version : Problem with setTimeout...

01-19-2003, 05:38 PM
I am trying to create a script that will move an image off the side of the screen gradually (but still pretty quickly). I currently have the code:

var distance = 50;

function move() {
If (distance < "500") {
zelda.style.left = distance;
setTimeout("move();", 100);

<img style="position: 'relative'; left: -100;" src="zelda.jpg" name="zelda" onMouseOver="move();">

For some reason whenever I run this code it stops when trying to call the move() function with an error of "object expected".
if i remove all the lines of code in the function and add them all back in individually it works up to the point where I add the setTimeout() command so I'm assuming it's a setTimeout() problem.

Thanks for your help.

01-19-2003, 06:14 PM
Try this:

var distance = 50;

function move() {
if (distance < 500)
document.getElementById('zelda').style.left = distance;
setTimeout("move()", 100);


<!-- html -->
<img style="position: relative; left: -100;" src="zelda.jpg" id="zelda" onMouseOver="move();">

You had a few things wrong. 1) your if statement had "If" instead of "if"... js is case sensitive; 2) since you were referencing the image by its name, your syntax for the css wasn't working, I changed it to an id; 3) your call to setTimeout doesn't take the semi-colon after the function call, I took it out.

Hope this helps.

- Terry

01-19-2003, 07:33 PM
thanks, it works fine now :)