Example 1 — Log movementX / movementY
MDN-style demo: print the delta while you move the mouse.
const log = document.getElementById("log");
document.addEventListener("mousemove", (event) => {
log.textContent =
`movement: ${event.movementX}, ${event.movementY}`;
}); How It Works
- Find the log node.
getElementById("log")is where the text will appear. - Listen for moves. Each
mousemovedelivers a freshMouseEvent. - Read both axes.
movementYis vertical;movementXis horizontal. - Update the UI. The template string replaces the log with the latest delta.

