1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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