SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    scarborough
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Moving div according to mouse and timer

    I used to have a script that moved a div according to the mouse. I also used a timer. I used the following formula to move the div.

    new position = ((old position * 9)+ current mouse position)/10

    Its particularly effective as you slowly move to the new position. Its recalculated every lets say tenth of a second.

    My question is
    1. how do I move a div every tenth of a second
    2. How do calculate the current mouse position

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by hairybobby View Post
    My question is
    1. how do I move a div every tenth of a second
    By using setInterval to run a function every 100 milliseconds.

    Quote Originally Posted by hairybobby View Post
    2. How do calculate the current mouse position
    With difficulty. The full details are covered at the event properties page, specifically, in the mouse position section of the page.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •