Example 1 — Log Coordinates (MDN)
Show screen and client X/Y while the mouse moves.
const screenLog = document.querySelector("#screen-log");
document.addEventListener("mousemove", function (e) {
screenLog.textContent =
"Screen X/Y: " + e.screenX + ", " + e.screenY +
"\nClient X/Y: " + e.clientX + ", " + e.clientY;
}); How It Works
- Listen for
mousemove. Fires often as the pointer moves. - Read
clientX/clientY. Viewport coordinates (MDN). - Compare to
screenX/screenY. Monitor vs window. - Update a log. Easy way to see live values.

