Javascript moving image


I have been tasked with using javascript to move an image of a bus across the screen from right to left. I have found some code that almost works, but I cannot get the bus to finish offscreen. I have tried changing the x-position to a negative number, but it doesn’t seem to work. If there are any javascript gurus out there, please take a look at the sample code at :

Any suggesstions on how to modify the existing code to achieve the desired effect would be greatly appreciated.


The amount that the bus position is decreased by, is determined by this line:

    var dec = Math.sqrt(xPos);

You will instead need to know both xPos and your target position, for example, xTarg, so that you can get the sqrt of xPos - xTarg