Skip to content

Instantly share code, notes, and snippets.

@billyxs
Last active August 29, 2015 14:02
Show Gist options
  • Save billyxs/982ab6fb5a0531147dc0 to your computer and use it in GitHub Desktop.
Save billyxs/982ab6fb5a0531147dc0 to your computer and use it in GitHub Desktop.
Get Mouse Event Position
function(e) {
if(!e) var e = window.event;
var posx = 0;
var posy = 0;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop
+ document.documentElement.scrollTop;
}
return {x: posx, y: posy};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment