1const el = document.getElementById('id')
2const elDistanceToTop = window.pageYOffset + el.getBoundingClientRect().top
1function getPosition(element) {
2 var xPosition = 0;
3 var yPosition = 0;
4
5 while(element) {
6 xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
7 yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
8 element = element.offsetParent;
9 }
10
11 return { x: xPosition, y: yPosition };
12}