Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save d1i1m1o1n/5ef3c8816001136b67be to your computer and use it in GitHub Desktop.
Save d1i1m1o1n/5ef3c8816001136b67be to your computer and use it in GitHub Desktop.
Данный сниппет поможет вам определить координаты пользовательского курсора практически во всех браузерах.
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