code: function getOffsetTop(el) {
      // Set our distance placeholder
      let distance = 0;
  
      // Loop up the DOM
      if (el.offsetParent) {
        do {
          distance += el.offsetTop;
          el = el.offsetParent;
        } while (el);
      }
  
      // Return our distance
      return distance < 0 ? 0 : distance;
    }
docs: www.gomakethings.com/how-to-get-an-elements-distance-from-the-top-of-the-page-with-vanilla-javascript/