movementY 只读特性在 MouseEvent interface provides the difference in the Y coordinate of the mouse pointer between the given event and the previous mousemove event. In other words, the value of the property is computed like this: currentEvent.movementY = currentEvent.screenY - previousEvent.screenY .

句法

var yShift = instanceOfMouseEvent.movementY;
					

返回值

数字

范例

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

HTML

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

JavaScript

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

结果

规范

规范 状态 注释
指针锁
The definition of 'MouseEvent.movementY' in that specification.
候选推荐 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
movementY Chrome 37
37
不支持 22 — 37 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge 13 Firefox 41
41
不支持 1 — 41 Prefixed
Prefixed Implemented with the vendor prefix: moz
IE No Opera Yes Safari 9
9
不支持 6 — 8 Prefixed
Prefixed Implemented with the vendor prefix: webkit
WebView Android 37
37
不支持 ? — 37 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Chrome Android 37
37
不支持 ? — 37 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android 41
41
不支持 4 — 41 Prefixed
Prefixed Implemented with the vendor prefix: moz
Opera Android Yes Safari iOS 8
8
不支持 6 — 8 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Samsung Internet Android 3.0
3.0
不支持 ? — 3.0 Prefixed
Prefixed Implemented with the vendor prefix: webkit

图例

完整支持

完整支持

不支持

不支持

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改: