Skip to content

Instantly share code, notes, and snippets.

@liqiang372
Last active February 9, 2017 22:10
Show Gist options
  • Save liqiang372/6ed46f64e8c89cc9265c to your computer and use it in GitHub Desktop.
Save liqiang372/6ed46f64e8c89cc9265c to your computer and use it in GitHub Desktop.
get cursor position on web
// this is a test file indeed
function getPosition(e) {
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
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