Skip to content

Instantly share code, notes, and snippets.

@wiki6
Forked from ondrek/mouse-position.js
Created March 7, 2022 07:19
Show Gist options
  • Select an option

  • Save wiki6/a3c8536127d49f74b879f2838081d983 to your computer and use it in GitHub Desktop.

Select an option

Save wiki6/a3c8536127d49f74b879f2838081d983 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment