title: jQuery problems with offset()
body: <p>I ran into a problem when creating a scroll for headlines.</p>
  <p>I looked at the element code, the code swears at the element &quot;..offset().top&quot;</p>
  <pre><code>$(function() {
  
      var header = $(&quot;header&quot;),
          introH = $(&quot;#intro&quot;).innerHeight(),
          scrollOffset = $(window).scrollTop()
  
      // scroll
      checkScroll(scrollOffset)
  
      $(window).on(&quot;scroll&quot;, function() {
          scrollOffset = $(this).scrollTop()
          checkScroll(scrollOffset)
  
      })
  
  
      function checkScroll() {
  
          if (scrollOffset &gt;= introH) {
              header.addClass(&quot;fixed&quot;)
          } else {
              header.removeClass(&quot;fixed&quot;)
          }
      }
  
      // scroll keys
      $(&quot;[data-scroll]&quot;).on(&quot;click&quot;, function(event) {
          event.preventDefault();
  
          var
              blockId = $(this).data(&quot;scroll&quot;),
              blockOffset = $(blockId).offset().top            /* This line */
  
  
          $(&quot;html, body&quot;).animate({
              scrollTop: blockOffset
          }, 500)
      })
  
  })
  </code></pre>
  <p><a href="https://i.stack.imgur.com/rmgb2.png" rel="nofollow noreferrer">enter image description here</a></p>