Encontre a altura do espaço acima do elemento usando JavaScript

// Vanila JS \\
var elem = document.getElementById( 'elementId' );  // select the element
var heightAbove = elem.offsetTop;  // get the height above the selected element

// Using jQuery \\
var elem = $('div[id]'); // select the element
var heightAbove = elem.offset().top; // get the height above the selected element
CoderHomie