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?
01-18-2013, 12:59 PM
Padonak
i would try to add blur() or focus() to ondblclick function
01-20-2013, 06:10 PM
ReFreezed
Listen for the mousedown event and return false from the handler to prevent the selection from happening.
01-21-2013, 07:04 AM
derekjackson
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: