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.
scroll to element's top position;
var rect = element.getBoundingClientRect(); var offsetTop = window.pageYOffset + rect.top - rect.height;