title: scrollTop() function infinite loop
body: <p>I know this subject has already been covered but I didn't find something as specific as my problem and the solutions I found didn't work for me (or i couldn't manage to make it work). I basically want to scroll to the top of the next element (a 100% height element) if I scroll down and if I scroll up from that element I would like it to scroll back to the top of the page.</p>
  
  <p>I currently have this :</p>
  
  <pre><code>var currDiv = 1;
  
  $(window).scroll(function(event)
  {
  
  if (currDiv == 1)
  {
  
      $('html, body').animate({  
          scrollTop:$('div.container').offset().top 
      }, 'slow');  
  
      currDiv = 2;
  
  }
  
  else if (currDiv == 2)
  {
  
      $('html, body').animate({  
          scrollTop:$('div.albums').offset().top 
      }, 'slow'); 
  
      currDiv = 1; 
  
  }
  
  });
  </code></pre>
  
  <p>I know it doesn't have the "up" and "down" events yet and that it is wrong on different levels, but it is a first attempt to cycle between them... The problem is that it triggers itself and it keeps cycling back between both elements... Any help would be greatly appreciated. </p>
  
  <p><a href="http://jsfiddle.net/644eghbw/1/" rel="nofollow">http://jsfiddle.net/644eghbw/1/</a> Here is a jsfiddle demonstrating the problem</p>