Screen Coordinates of a element, via Javascript

后端 未结 3 1508
悲&欢浪女
悲&欢浪女 2020-12-01 07:47

I\'m trying to get the screen coordinates (that is, relative to the top left corner of the screen) of an element in a browser window. It\'s easy to get the size and position

3条回答
  •  暖寄归人
    2020-12-01 08:10

    I don't think this is possible.

    The element coordinates are relative to the top left corner of the rendered page.

    The window coordinates are relative to the screen.

    There is, to my knowledge, nothing that relates the top left corner of the rendered page to the top left corner of the window. So there's no way to account for borders, scrollbars, chrome, etc. So I think you're sunk on this one.

提交回复
热议问题