MouseEvent.screenX

这篇翻译不完整。请帮忙从英语翻译这篇文章

 screenX 是只读属性,他提供了鼠标相对于屏幕坐标系的水平偏移量。

语法

var pixelNumber = instanceOfMouseEvent.screenX

返回值

一个双浮点值。早期版本的规格定义这是一个 整数指的像素数。有关详细信息,请参见浏览器兼容性部分。

示例

<html>
<head>
<title>screenX\screenY example</title>

<script type="text/javascript">

function showCoords(evt){
  alert(
    "screenX value: " + evt.screenX + "\n"
    + "screenY value: " + evt.screenY + "\n"
  );
}

</script>
</head>

<body onmousedown="showCoords(event)">
<p>To display the mouse coordinates click anywhere on the page.</p>
</body>
</html>

当你的事件绑定在窗口,文档或者其他元素上时,你可以通过event对象获得这个属性值(比如一个点击)。如下面的示例:

function checkClickMap(e) {
  if (e.screenX < 50) doRedButton();
  if (50 <= e.screenX && e.screenX < 100) doYellowButton();
  if (e.screenX >= 100) doRedButton();
}

规范

Specification Status Comment
CSS Object Model (CSSOM) View Module
screenX
Working Draft Redefines MouseEvent from long to double. 
Document Object Model (DOM) Level 3 Events Specification
MouseEvent.screenX
Obsolete No change from Document Object Model (DOM) Level 2 Events Specification.
Document Object Model (DOM) Level 2 Events Specification
MouseEvent.sceenX
Obsolete Initial definition

浏览器兼容性

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) 6 (Yes) (Yes)
Redefined from long to double 56 ? ? ? ? ?
Feature Android Webview Chrome for Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)
Redefined from long to double 56 56 ? ? ? ? ?

See also

文档标签和贡献者

 此页面的贡献者: snowHe2017
 最后编辑者: snowHe2017,