Skip to content

[CSSOM] There is no way to get correct viewport position in relation to the screen #5814

@ArkadiuszMichalski

Description

@ArkadiuszMichalski

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions