--- title: MouseEvent.screenY slug: Web/API/MouseEvent/screenY tags: - API - 参考 - 属性 - 鼠标 - 鼠标事件 translation_of: Web/API/MouseEvent/screenY ---

{{APIRef("DOM Events")}}

 screenX 是 MouseEvent 的只读属性,提供鼠标在全局(屏幕)中的水平坐标(偏移量)。

语法

var pixelNumber = instanceOfMouseEvent.screenY

返回值

一个double值。早期版本的规范定义将其一个整数值的像素数。有关详细信息,请参见浏览器兼容性部分。

示例

这个例子展示了当触发 {{Event("mousemove")}} 事件时鼠标的坐标。

HTML

<p>Move your mouse to see its position.</p>
<p id="screen-log"></p>

JavaScript

let screenLog = document.querySelector('#screen-log');
document.addEventListener('mousemove', logKey);

function logKey(e) {
  screenLog.innerText = `
    Screen X/Y: ${e.screenX}, ${e.screenY}
    Client X/Y: ${e.clientX}, ${e.clientY}`;
}

结果

{{EmbedLiveSample("Example")}}

规范

Specification Status Comment
{{SpecName('CSSOM View','#dom-mouseevent-screeny', 'screenY')}} {{Spec2('CSSOM View')}} Redefines {{domxref("MouseEvent")}} from long to double. 
{{SpecName('DOM3 Events','#widl-MouseEvent-screenY','MouseEvent.screenY')}} {{Spec2('DOM3 Events')}} No change from {{SpecName('DOM2 Events')}}.
{{SpecName('DOM2 Events','#Events-MouseEvent','MouseEvent.sceenY')}} {{Spec2('DOM2 Events')}} Initial definition

浏览器兼容性

{{ CompatibilityTable() }}

Feature Edge Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown()}} {{CompatVersionUnknown()}} 6 {{CompatVersionUnknown()}} {{CompatVersionUnknown()}}
Feature Edge Firefox Mobile (Gecko) Android IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown()}} {{CompatVersionUnknown()}} {{CompatVersionUnknown()}} {{CompatVersionUnknown()}} {{CompatVersionUnknown()}}

参见