If I zoom in a page as far as it will go and move the mouse very slowly (a pixel at a time) across the page, the generated mousemove
events' clientX
/clientY
values have no fractional part, and therefore lose precision. (Often, several mousemove
events with the exact same co-ordinate values get fired in a row, because the mouse did move, but moved less than one whole CSS-pixel.) This is true for me on all browsers I have for Windows 10 -- Chrome, Firefox, Opera and Edge.
MDN's "Browser Compatibility" section states that clientX
was changed from long
to double
in Chrome 56. So, this change seems to have been recently reverted, in Chrome's case at least.
The screenX
/screenY
co-ordinate values seem to be in device pixels, rather than CSS pixels, and therefore invariant to zooming. This was true for Firefox, Chrome, Edge and Opera when I tried. This seems promising, but without knowing the edges of the screen rectangle in device pixels also it may not be much use to me. (It also looks like future draft specs expect screenX
/Y
to be in CSS pixels anyway.)
So: is there any way I'm not seeing to get the mouse position without loss of precision at high zoom levels?