Created
December 16, 2015 11:05
-
-
Save ahvonenj/3f4c2d3ae412402bb34e to your computer and use it in GitHub Desktop.
Canvas pointer coords no matter where and how big canvas is
This file contains hidden or 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
relMouseCoords: function(canvas, e) | |
{ | |
var rect = canvas.getBoundingClientRect(); | |
var x = e.clientX - rect.left; | |
var y = e.clientY - rect.top; | |
return { x: x, y: y }; | |
} | |
relTapCoords: function(canvas, e) | |
{ | |
var rect = canvas.getBoundingClientRect(); | |
var x = e.touches[0].clientX - rect.left; | |
var y = e.touches[0].clientY - rect.top; | |
return { x: x, y: y }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment