MDN Web Docs

Value

A number. Always zero on any MouseEvent other than mousemove, and any PointerEvent other than pointermove or pointerrawupdate.

Examples

Log mouse movement for mousemove events

This example logs the amount of mouse movement using movementX and movementY.

HTML

html

<p id="log">Move your mouse around inside this element.</p>

JavaScript

js

const log = document.getElementById("log");
function logMovement(event) {
  log.innerText = `movement: ${event.movementX}, ${event.movementY}\n${log.innerText}`;
}
document.addEventListener("mousemove", logMovement);

Result

Specifications

Specification
Pointer Lock 2.0
# dom-mouseevent-movementy

Browser compatibility

See also

Help improve MDN

Yes No

Learn how to contribute

This page was last modified on by MDN contributors.

Read the original on developer.mozilla.org ↗