Last active
January 8, 2017 11:33
-
-
Save vincentorback/3a1941bf7128f4f4fd94ced9b08f31ca to your computer and use it in GitHub Desktop.
getMousePosition.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function getMousePosition (e) { | |
let posX = 0 | |
let posY = 0 | |
if (!e) { | |
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