W3C home > Mailing lists > Public > public-css-archive@w3.org > December 2020

[csswg-drafts] [CSSOM] There is no way to get correct viewport position in relation to the screen (#5814)

From: ArkadiuszMichalski via GitHub <sysbot+gh@w3.org>
Date: Mon, 21 Dec 2020 13:19:45 +0000
To: public-css-archive@w3.org
Message-ID: <issues.opened-772164084-1608556784-sysbot+gh@w3.org>
ArkadiuszMichalski has just created a new issue for https://github.com/w3c/csswg-drafts:

== [CSSOM] There is no way to get correct viewport position in relation to the screen ==
Hi, actually there is no way to get correct  viewport position in relation to the screen (I mean whole screen). We have this properties:

https://developer.mozilla.org/en-US/docs/Web/API/Window/outerWidth
https://developer.mozilla.org/en-US/docs/Web/API/Window/outerHeight
https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth
https://developer.mozilla.org/en-US/docs/Web/API/Window.innerHeight

but the difference between `window.outerHeight - window.innerHeight` represents both toolbars (above and belove viewport).  So I can't determine how many space the top bar takes up. This is especially noticeable when something like the status bar or devs tools appear at the bottom. For this reason, I am not able to determine the position of the element relative to the entire screen (equivalence for `event.screenX` and  `event.screenY`).

Similar questions raised by the community:
https://stackoverflow.com/questions/37342914/how-to-find-the-absolute-the-coordinates-of-an-html-element
https://stackoverflow.com/questions/6107357/how-can-i-find-the-position-of-an-html-element-relative-to-the-entire-desktop-sc/29554744
https://stackoverflow.com/questions/13254070/how-do-i-get-the-viewport-position-relative-to-the-screen
https://stackoverflow.com/questions/55115381/how-to-get-absolute-position-of-an-element-relative-to-the-whole-screen
https://stackoverflow.com/questions/29369696/javascript-element-position-relative-to-screen
https://stackoverflow.com/questions/2337795/screen-coordinates-of-a-element-via-javascript
https://stackoverflow.com/questions/12057455/get-screenx-for-dom-element-in-javascript

The lack of such an option is made by intention? If not, one of the solutions below might fix the problem:
- add to `window` some new x/y cords that expose position viewport related to screen
- add to `element`  some x/y cords that expose position related to screen (equivalence for `event.screenX` and  `event.screenY`)
- add to window some properties that expose how much space each toolbars takes (I mean top, botoom, left and right toolbar) .

or any other that will solve the problem described here.




Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/5814 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Monday, 21 December 2020 13:19:47 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 5 July 2022 06:42:24 UTC