Re: [csswg-drafts] [cssom-view] window.innerScreenX windows.innerScreenY (#809)

Despite the deficiency in the spec, which I would also love to see fixed, there is actually a fairly reliable way to obtain the position of the viewport, which no one has mentioned so far in this thread. I found it mentioned in a few of the StackOverflow questions linked in #5814 (e.g. https://stackoverflow.com/a/28136985):
```
innerScreenX = mouseEvent.screenX - mouseEvent.clientX;
innerScreenY = mouseEvent.screenY - mouseEvent.clientY;
```

One obvious downside is that you need to obtain a MouseEvent to do this (e.g. from a `click` event), so for keyboard-only users, you'll need to fall back to `window.screenX`/`window.screenY`.

A less obvious downside is that on Chromium, the coordinate space of MouseEvent#screenX/Y uses device pixels, while MouseEvent#clientX/Y uses CSS pixels, so if the user has zoomed in or out, the result will be incorrect. On Firefox and in the draft spec they're both using CSS pixels. It is possible to work around this with a bit of additional effort though: please see my bug report at https://issues.chromium.org/issues/343009010 and the demo there for an example.

-- 
GitHub Notification of comment by MatmaRex
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/809#issuecomment-2134169650 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 28 May 2024 00:28:08 UTC