How can I find out how far above the page an element is positioned?

Discussion in 'JavaScript' started by SoftLink, Jun 18, 2025.

  1. #1
    Basically, I've got an li in a dropup menu that is above the page top.
    I'm using el.getBoundingClientRect().top and it's returning a number much greater (after Math.abs) than where the element is actually positioned.

    I add padding to the top of the page to see where the element is actually positioned.

    The element is about 150 pixels above the top of the page visually but getBoundingClientRect is returning over 400 for the element's top.
    The page's scrollY is 0 so it's not a scrolling issue.

    Why is the number so far off and how can I find out where the element really is?
     
    SoftLink, Jun 18, 2025 IP