I want to know how to use JavaScript to get the distance of an element from the top of the page not the parent element.
var distanceTop = element.getBoundingClientRect().top;
For details vist a link:
https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect