title: Detecting if a user has scrolled away from the top
body: <p>The obvious answer to this is to simply attach an event to the scroll event:</p>
  
  <pre><code>var scrolled = false;
  
  $(window).scroll(function() {
     if($(window).scrollTop() &gt; 0) {
         scrolled = true;
     } else {
         scrolled = false;
     }
  });
  </code></pre>
  
  <p>However, creator of jQuery, <a href="http://ejohn.org/blog/learning-from-twitter/" rel="noreferrer">John Resig's blogpost from 2011</a> states: <strong>It’s a very, very, bad idea to attach handlers to the window scroll event.</strong></p>
  
  <p>And recommends the following:</p>
  
  <pre><code>var didScroll = false;
  
  $(window).scroll(function() {
      didScroll = true;
  });
  
  setInterval(function() {
      if ( didScroll ) {
          didScroll = false;
          // Check your page position
      }
  }, 250);
  </code></pre>
  
  <p>Has anything changed in the past five years? Is John Resig's solution still the best?</p>