Created
September 7, 2013 10:13
-
-
Save delapuente/6474431 to your computer and use it in GitHub Desktop.
Useful function to obtain canvas relative mouse coordinates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var canvasX, canvasY; | |
theCanvas.onmousemove = transformIntoCanvasRelative; | |
function transformIntoCanvasRelative(evt) { | |
var canvas = evt.target; | |
var rect = canvas.getBoundingClientRect(); | |
canvasX = evt.clientX - rect.left; | |
canvasY = evt.clientY - rect.top; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment