Skip to content

Instantly share code, notes, and snippets.

@jtenner
Last active December 28, 2015 17:09
Show Gist options
  • Save jtenner/7533847 to your computer and use it in GitHub Desktop.
Save jtenner/7533847 to your computer and use it in GitHub Desktop.
//let's cache the event
var priorEvt;
function getMousePos(evt) {
//set and store..
priorEvt = evt = evt || priorEvt;
//get the bounding rectangle
var rect = canvas.getBoundingClientRect();
//lastly, return the x and y coordinates
if (evt)
return {
x: evt.clientX - rect.left,
y: evt.clientY - rect.top
};
return {
x: 0,
y: 0
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment