www.webdeveloper.com
Results 1 to 6 of 6

Thread: ondblclick selects image

  1. #1
    Join Date
    Feb 2005
    Location
    Norwich, UK
    Posts
    138

    ondblclick selects image

    Hi,
    I'm writing a script that makes an IMG sprite move around the page to wherever the user clicks. If they double click then the sprite moves twice as fast.

    My script gets the mouse position on the click, and repeatedly increments the IMG's left and top values until it reaches the click location.

    For some reason, the ondblclick event works as intended, but selects the IMG so it turns blue. Any idea why this is or what I could do to stop it?
    _____________________________________________

    http://www.djillustration.com

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    i would try to add blur() or focus() to ondblclick function
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  3. #3
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    Listen for the mousedown event and return false from the handler to prevent the selection from happening.
    New to web development or in need of a good reference? Check out the Mozilla Developer Network or W3Schools.

  4. #4
    Join Date
    Feb 2005
    Location
    Norwich, UK
    Posts
    138
    Thanks for the suggestions. I'm still trying to get my head around JavaScript so I'm not too sure how to implement them?

    My event code is
    Code:
    document.ondblclick = function(){newTarg(8)};
    Then the newTarg function flags the IMG as moving, and sets TargetX and TargetY variables to the click location

    Then I have a recursive function called moveImg that compares the IMG's current position to the targetX and Y, and increments its Left and Top CSS properties if needed.

    I assume I'd put 'return false' at the end of the ondblclick function? So:
    Code:
    document.ondblclick = function(){newTarg(8);return false;};
    Cheers for the help, but I'm a bit stumped...
    _____________________________________________

    http://www.djillustration.com

  5. #5
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    document.onmousedown = function(){ return false; }; //prevents selection
    New to web development or in need of a good reference? Check out the Mozilla Developer Network or W3Schools.

  6. #6
    Join Date
    Feb 2005
    Location
    Norwich, UK
    Posts
    138
    That's done it - thanks!
    _____________________________________________

    http://www.djillustration.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles