MouseEvent: movementY プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

movementYMouseEvent インターフェイスの読み取り専用プロパティで、直前の mousemove イベントとこのイベントのマウスポインターの Y 座標の差を示します。このプロパティの値は currentEvent.movementY = currentEvent.screenY - previousEvent.screenY のように計算されます。

警告: ブラウザーは movementYscreenY仕様で定義されているものとは異なる単位を使用します。ブラウザーとオペレーティングシステムによって、 movementY の単位は物理ピクセルであったり、論理ピクセルであったり、 CSS ピクセルであったりします。

数値です。 mousemove 以外の MouseEvent では常に 0 です。

この例は movementXmovementY を使用して、マウスの移動量を記録します。

HTML

html
<p id="log">マウスを動かしてください。</p>

JavaScript

js
function logMovement(event) {
  log.innerText = `移動量: ${event.movementX}, ${event.movementY}\n${log.innerText}`;
}

const log = document.getElementById("log");
document.addEventListener("mousemove", logMovement);

結果

仕様書

Specification
Pointer Lock 2.0
# dom-mouseevent-movementy

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
movementY

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Requires a vendor prefix or different name for use.
Has more compatibility info.

関連情報