title: Get item offset from the top of page
body: <p>I am trying to get the top offset of a div, and I have the following code that gets run when the page gets scrolled:</p>
  
  <pre><code>var $elem = document.querySelector(selector);
  var elemTop = $elem.offsetTop;
  console.log(elemTop);
  </code></pre>
  
  <p>But when I scroll it always prints <code>0</code> to the console, even though the element is below the fold.</p>