Getting the position of the mouse pointer is an important event when an event occurs. This was originally a very simple question, but due to the browser's incompatibility, the development brought challenges. Different browsers define different attributes in their respective event objects, as described in the chart below.
| Property |
Description |
Compatibility |
| ClientX |
Position x-axis coordinates with the top-left corner of the browser window as the origin point |
All browsers, not compatible with Safari |
| ClientY |
Position y-axis coordinates with the upper-left corner of the browser window as the origin point |
All browsers, not compatible with Safari |
| OffsetX |
Position x-axis coordinates with the top-left corner of the target object of the current event as the origin point |
All browsers, not compatible with Mozilla |
| OffsetY |
Positions the y-axis coordinates with the top-left corner of the target object of the current event as the origin point |
All browsers, not compatible with Mozilla |
| PageX |
Position x-axis coordinates with the top-left corner of the document object (that is, the Documents window). |
All browsers, not compatible with IE |
| Pagey |
Position the y-axis coordinates with the top-left corner of the document object (that is, the Documents window). |
All browsers, not compatible with IE |
| ScreenX |
The upper-left corner of the computer screen is the origin and the x-axis coordinates are located . |
All browsers |
| screeny |
computer screen the upper-left corner is the origin. , positioning y-axis coordinates |
All browsers |
| layerx |
(if not, the Document object) the upper-left corner is the origin, positioning x-axis coordinates |
mozilla and Safari |
| Layery |
nearest absolute position parent element (or Document object if not) the upper-left corner is the origin, and the y-axis coordinates are positioned |
Mozilla and Safari |
Mouse pointer location resolution and compatibility method