SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript moving image

    Hello,

    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 :

    http://www.danshamptons.com/anim/

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

    Thanks,
    Colin

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    The amount that the bus position is decreased by, is determined by this line:

    Code javascript:
        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
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •