MouseEvent screenX Property

Definition and Usage

The screenX property returns the horizontal coordinate of the mouse pointer at the time of the event trigger (relative to the user's computer screen).

Tip:To get the vertical coordinate of the mouse pointer (relative to the user's computer screen), use screenY Attribute.

Note:This property is read-only.

Instance

Example 1

Get the coordinate of the mouse pointer relative to the screen when the mouse button is clicked on an element:

var x = event.screenX;     // Get the horizontal coordinate
var y = event.screenY;     // Get the vertical coordinate
var coor = "X coords: " + x + ", Y coords: " + y;

Try It Yourself

Example 2

Demonstrate the difference between clientX and clientY as well as screenX and screenY:

var cX = event.clientX;
var sX = event.screenX;
var cY = event.clientY;
var sY = event.screenY;
var coords1 = "client - X: " + cX + ", Y coords: " + cY;
var coords2 = "screen - X: " + sX + ", Y coords: " + sY;

Try It Yourself

Syntax

event.screenX

Technical Details

Return value: Digital value, representing the horizontal coordinate of the mouse pointer in pixels.
DOM Version: DOM Level 2 Events

Browser Support

Atribute Chrome IE Firefox Safari Opera
screenX 支持 支持 支持 支持 支持

相关页面

HTML DOM 参考手册:MouseEvent screenY 属性

HTML DOM 参考手册:MouseEvent clientX 属性

HTML DOM 参考手册:MouseEvent clientY 属性

HTML DOM 参考手册:MouseEvent offsetX 属性

HTML DOM 参考手册:MouseEvent offsetY 属性