I have the following code:
http://www.project-vanquish.co.cc/gridtest/drag-grid.html
The plan is to allow the user to control that div (with the smiley face) in 3 ways:
1 – by the Cursor Keys on the keyboard
2 – by dragging the div
3 – by clicking on an area and the div will move to that position
The problem I have is that when I click the page the div seems slightly offset to what it should be 🙁
Also, the “click to move” method doesn’t work at all in IE.
I thought I had cracked this last night, evidently not…
You need to adjust the
mouse coordinatesbecause they areabsolute(from the event object) but you have work to withrelativeon the map.So you need the coordinates of the map and subtract them from the mouse click coordinates every time a click occures.
You also have to normalize the click coordinates to deal with the center of the character (instead of the top left corner). So you need to subtract the half of the character’s width and height from the mouse coordinates.
[See it in action]