JS Obtenha a distância do elemento do topo
const el = document.getElementById('id')
const elDistanceToTop = window.pageYOffset + el.getBoundingClientRect().top
florinrelea
const el = document.getElementById('id')
const elDistanceToTop = window.pageYOffset + el.getBoundingClientRect().top
function getPosition(element) {
var xPosition = 0;
var yPosition = 0;
while(element) {
xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
element = element.offsetParent;
}
return { x: xPosition, y: yPosition };
}