MouseEvent: High precision mouse position when the page is zoomed in?

ⅰ亾dé卋堺 提交于 2021-02-19 01:53:47

问题


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?

来源:https://stackoverflow.com/questions/47019163/mouseevent-high-precision-mouse-position-when-the-page-is-zoomed-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!