I have a div
with float: right
and I'm trying to get its distance from the top of the viewport. In every browser except Safari I'm getting the expected results from element.getBoundingClientRect().top
. Safari appears to be reporting the element's distance from the top of the page rather than the viewport. This is contrary to what is defined in the spec for this method (as I understand it). Is Safari just not following the rules here, or are other browsers being more forgiving of some mistake of mine that I'm not seeing?
The "getBoundingClientRect is not a function" error occurs for multiple reasons: calling the getBoundingClientRect() method on a value that is not a DOM element. placing the JS script tag above the code that declares the DOM elements. misspelling getBoundingClientRect (it's case sensitive).
getBoundingClientRect() method returns a DOMRect object providing information about the size of an element and its position relative to the viewport.
Border, padding and margin are not included.
This appears to be a bug that effects the way that Safari reports element and scroll locations on its load event. If you run the exact same call with a 500ms timeout everything works as expected.
I will update when I hear back on my bug report.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With