Example 1 — Read x on Move
Print viewport X and Y while the mouse moves.
document.addEventListener("mousemove", (event) => {
console.log(event.x, event.y);
}); How It Works
- Listen for moves. Every pointer move fires
mousemove. - Read the short names.
event.x/event.yare viewport coordinates. - Same as client. Values match
clientX/clientY. - Use the numbers. Great for fixed UI, tooltips, and simple hit tests.

