title: Fade in and out multiple times
body: <p>Hy everione this is my code for resizing the window and some other elements and in the scroll function i have a div that apears and desapears in different pozition of the screen depending on the x.top of the window. </p>
  
  <p>Ok now the problem on the scroll function when i go to hidden_div2 the text inside the <p> fades in ok my problem is when u come back to first div the text fades in and out 6 times. HELP :(</p>
  
  <pre><code>var image_position = new Array();
  var i = 0;
  
  function imageResize() {
      $('.images').find('img').each( function (){
          var dwidth = $(window).width();
          var dheight = $(window).height();
  
          var imagewidth = $(this).attr('width');
          var imageheight = $(this).attr('height');
          var imageratio = imagewidth / imageheight;
  
          var imagehresize = dwidth;
          var imagevresize = imagehresize * imageratio;
  
          var x = $(this).parent('div').position();
          image_position[i] = x.top;
  
          var boxleft = dwidth / 6;
  
          i++;
      });
  
  }
  
  $(window).scroll(function(){
      var x = $('.hidden_div').offset();
      var img1 = image_position[2];
      var img2 = image_position[3];
  
      if(x.top &gt; img1){
          $('.hidden_div').css('z-index', '40');
          $('.hidden_div p').fadeOut(2000);
          $('.hidden_div2').css('z-index', '130');
          $('.hidden_div2 p').fadeIn(2000);
  
      }
      else if(x.top &lt; img1){
          $('.hidden_div').css('z-index', '130');
          $('.hidden_div p').fadeIn(2000);
          $('.hidden_div2').css('z-index', '40');
          $('.hidden_div2 p').fadeOut(2000);
      }
  
  });
  </code></pre>