title: show/hide div using scrollTop
body: <p>I'm trying to create a script which would show div if  500px &lt; scrollTop &lt; 800px otherwise it would be hidden. So if my scroll is from 0 to 500 and from 800 and more it is hidden and between 500 and 800 it is shown. I'm new to javascript but this is what I have tried:</p>
  
  <pre><code>$(document).ready(function(){ 
  
  $(window).scroll(function(){
      if ($(this).scrollTop() &gt; 500) {
          $('.myDiv').fadeIn();
      } else {
          $('.myDiv').fadeOut();
      }
      if ($(this).scrollTop() &gt; 800) {
          $('.myDiv').fadeOut();
      }
  });
  </code></pre>
  
  <p>However after scrolling to 800 it bugs and starts endlessly hiding and showing. Any way to fix it please?</p>