About
mousemove is an event that occurs when the pointing device is moved while it is over an element.
The onmousemove attribute may be used with most elements.
It permits to track the mouse location.
Demo
- The callback method that prints the location of the mouse that is wrapped in a debounce function to not print for each move.
function onMouseMove(e){
console.log(new Date().toLocaleString()+": Position: x: "+e.x+ ", y:"+ e.y);
}
let debouncedMouseMove = debounce(onMouseMove, 500);
- The event listener that subscribe to the event with the wrapped callback method
document.addEventListener('mousemove', debouncedMouseMove);
- The output: Move your mouse above the console region and stops it