get coordinates from mouse javascript code example
Example 1: how to get mouse x and y in javascript
document.addEventListener("mousemove", () => {
let mousex = event.clientX;
let mousey = event.clientY;
console.log([mousex, mousey]);
});
Example 2: 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);
}