MouseEvent.screenY

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.

screenYMouseEvent 的只读属性,提供鼠标在全局(屏幕)中的垂直坐标(偏移量)。

一个双精度浮点数(double)。

早期版本的规范定义将其一个整数值的像素数。

示例

这个示例展示了当触发 mousemove 事件时鼠标的坐标。

HTML

html
<p>移动鼠标以查看其坐标。</p>
<p id="screen-log"></p>

JavaScript

js
let screenLog = document.querySelector("#screen-log");
document.addEventListener("mousemove", logKey);
function logKey(e) {
  screenLog.innerText = `
    屏幕坐标 X/Y: ${e.screenX}, ${e.screenY}
    客户端坐标 X/Y: ${e.clientX}, ${e.clientY}`;
}

结果

规范

Specification
UI Events
# dom-mouseevent-screeny

浏览器兼容性

BCD tables only load in the browser

参见