I am attempting to determine the exact positioning of a background image that has been shifted off the viewport by applying specific CSS rules. This may be difficult to explain in words, so I have provided a visual example:
Black box: Viewport
Red box: Container with a background image applied
Blue box: Container containing a link
When using getBoundingClientRect
on the container with the background image, I receive coordinates of 0px 0px
. This is logical as the container is within the viewport, starting at the top left corner.
However, the background image within that container has been shifted to the left (or potentially also upwards), meaning the actual coordinates should differ from those of the container itself. This leads me to my question:
How can I determine the position of the green point on any page experiencing this particular scenario without altering anything? Essentially, I need to figure out how many pixels the browser cuts out of the background image's display.
Currently, I am utilizing JavaScript to interact with the Web/DOM API. I am open to exploring any methods, even undocumented ones, to address this issue.