J
Jupiter49
I'm trying to move pictures around on the screen, with a slight delay
between the first picture and second picture (following onmousemove).
When I add the setTimeout function I must be doing it wrong because
the function that calculates the new coordinates for the picture
returns 32 million and change instead of the coordinate. This causes
the picture to not be able to appear on the display, obviously.
Here's the calling code (snipped for readability) that works without
setTimeout:
*********************************
function moveDucks(xPos, yPos) {
baby1.left = newDuckPos(yPos - 30, xPos - 30)
baby1.top = newDuckPos(xPos + 30, yPos + 30)
}
function newDuckPos(currentPos, duckPos) {
newPos = Math.min(Math.max(currentPos, duckPos+3), duckPos+17)
return(document.getElementById) ? newPos + "px" : newPos
}
****************************************
The above returns the correct "newPos" and everything is hunky dory.
Then I
try to use setTimeout:
****************************************
function moveDucks(xPos, yPos) {
baby1.left = setTimeout("newDuckPos("+yPos+" - 30, "+xPos+" -
30)",500);
clearTimeout;
baby1.top = setTimeout("newDuckPos("+xPos+" + 30, "+yPos+" +
30)",500);
clearTimeout;
}
**************************************
The above causes the newDuckPos to return as 32 million+ instead of
normal corrdinates. I am far too new to Javascript to have a clue. I
did follow the i/o enough to see that the the coordinates have valid
values when they reach newDuckPos (I output them to display to make
sure). Then newDuckPos calculates them and before it sends them back
I intercept them again. Again, the values look good.
Then newDuckPos returns them and they get munged.
Can anybody steer me in the right direction to figure this out?
Thanks.
between the first picture and second picture (following onmousemove).
When I add the setTimeout function I must be doing it wrong because
the function that calculates the new coordinates for the picture
returns 32 million and change instead of the coordinate. This causes
the picture to not be able to appear on the display, obviously.
Here's the calling code (snipped for readability) that works without
setTimeout:
*********************************
function moveDucks(xPos, yPos) {
baby1.left = newDuckPos(yPos - 30, xPos - 30)
baby1.top = newDuckPos(xPos + 30, yPos + 30)
}
function newDuckPos(currentPos, duckPos) {
newPos = Math.min(Math.max(currentPos, duckPos+3), duckPos+17)
return(document.getElementById) ? newPos + "px" : newPos
}
****************************************
The above returns the correct "newPos" and everything is hunky dory.
Then I
try to use setTimeout:
****************************************
function moveDucks(xPos, yPos) {
baby1.left = setTimeout("newDuckPos("+yPos+" - 30, "+xPos+" -
30)",500);
clearTimeout;
baby1.top = setTimeout("newDuckPos("+xPos+" + 30, "+yPos+" +
30)",500);
clearTimeout;
}
**************************************
The above causes the newDuckPos to return as 32 million+ instead of
normal corrdinates. I am far too new to Javascript to have a clue. I
did follow the i/o enough to see that the the coordinates have valid
values when they reach newDuckPos (I output them to display to make
sure). Then newDuckPos calculates them and before it sends them back
I intercept them again. Again, the values look good.
Then newDuckPos returns them and they get munged.
Can anybody steer me in the right direction to figure this out?
Thanks.