This changes depending on the element's offsetParent. You might be able to do this using getBoundingClientRect and adding the scrollTop.

https://developer.mozilla.org/en-US/docs/Web/API/Element.getBoundingClientRect