Skip to content

Instantly share code, notes, and snippets.

@ondrek
Created October 31, 2013 15:15
Show Gist options
  • Save ondrek/7251430 to your computer and use it in GitHub Desktop.
Save ondrek/7251430 to your computer and use it in GitHub Desktop.
How to get mouse position in Javascript
window.onmousemove = logMouseMove;
function logMouseMove(event) {
e = e || window.event;
mousePos = { x: e.clientX, y: e.clientY };
console.log(mousePos);
}
@dsaavedr
Copy link

@kingname, I think your error lies in executing regardless. His code is e = event || window.event so, even if the window.event is undefined, the code still works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment