DOM MouseEvent.clientX Property
The clientX and clientY properties give the position of the mouse pointer when the event happened, relative to the viewport.
Description
The read-only clientX and clientY properties give the pointer's coordinates within the viewport at the time of the event, unaffected by scrolling. Related properties give other reference points: pageX/pageY relative to the whole document, offsetX/offsetY relative to the target element, and screenX/screenY relative to the screen.
Because they're relative to the viewport, clientX and clientY match the coordinates used by getBoundingClientRect(), making it easy to work out where inside an element the pointer is: e.clientX - rect.left.
For dragging, listen for pointermove rather than mousemove, so the same code works with touch and pen input, and call setPointerCapture() on the dragged element so it keeps receiving events even if the pointer moves outside it.
Syntax
event.clientX
event.clientYValue
The horizontal (or vertical) pointer position in pixels, relative to the viewport.
Example
Browser Support
The following information will show you the current browser support for the MouseEvent.clientX property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





