Answers for "how to get mouse position in java script"

2

how to get mouse x and y in javascript

document.addEventListener("mousemove", () => {
  let mousex = event.clientX; // Gets Mouse X
  let mousey = event.clientY; // Gets Mouse Y
  console.log([mousex, mousey]); // Prints data
});
Posted by: Guest on September-23-2020
8

Javascript track mouse pointer

var pointerX = -1;
var pointerY = -1;
document.onmousemove = function(event) {
	pointerX = event.pageX;
	pointerY = event.pageY;
}
setInterval(pointerCheck, 1000);
function pointerCheck() {
	console.log('Cursor at: '+pointerX+', '+pointerY);
}
Posted by: Guest on November-03-2020

Code answers related to "how to get mouse position in java script"

Code answers related to "Javascript"

Browse Popular Code Answers by Language