Skip to content

Instantly share code, notes, and snippets.

@GideonPARANOID
Last active December 31, 2015 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GideonPARANOID/7987806 to your computer and use it in GitHub Desktop.
Save GideonPARANOID/7987806 to your computer and use it in GitHub Desktop.
As I always forget how to effectively do this.
/**
* @param eve an event object from function listening on the element, such as mousedown
* @return object describing the position of the mouse on the canvas
*/
function mouse_pos(eve) {
var rect = eve.target.getBoundingClientRect();
return {
y : eve.clientY - rect.top,
x : eve.clientX - rect.left
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment