title: jquery setInterval or scroll
body: <p>I am working on a project where i need to listen to the <code>scroll</code> event.. i wonder what is a better approach..</p>
  
  <h1>1st Approach</h1>
  
  <pre><code> function scroll() {
      if ($(window).scrollTop() &gt; 200) {
          top.fadeIn();
      } else {
          top.fadeOut();
      }
      if (menuVisible) {
        quickHideMenu();
      }
  }
  </code></pre>
  
  <h1>2nd Approach</h1>
  
  <pre><code>      function scroll() {
            didScroll = true;
        }
  
        setInterval(function() {
            if ( didScroll ) {
                didScroll = false;
                if ($(window).scrollTop() &gt; 200) {
                    top.fadeIn();
                } else {
                    top.fadeOut();
                }
                if (menuVisible) {
                  quickHideMenu();
                }
            }
        }, 250);
  </code></pre>
  
  <p>Thanks :)</p>