2012-08-30 25 views
1

任何人都可以使用这个JavaScript来帮助我吗?jQuery .scrollTop混淆

我想div显示,当你超过1000个像素向下滚动,目前它与下面的脚本,但滚动时,它立即显示。

我试着将它设置为>1000,并没有显示在所有?

任何想法?

$(window).scroll(function(){ 

    /* Check the location of each desired element */ 
    $('.hideme').each(function(i){ 

     /* If the object is completely visible in the window, fade it in */ 
     if ($(this).scrollTop() < 1000){ 
      $(this).animate({'opacity':'1'},900); 
     } 
    }); 
}); 
+0

ü可以包括你的CSS与它一起请。 –

回答

1

希望这会有帮助吗?

<html> 
<head> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> 
    <script> 
    $(window).scroll(function(){ 
     /* Check the location of each desired element */ 
     $('.hideme').each(function(i){ 
      console.log($(window).scrollTop()); 
      if ($(window).scrollTop() < 500){ 
       $(this).stop().animate({ 
        opacity: 1.0 
       },900); 
      } else { 
       $(this).stop().animate({ 
        opacity: 0.0 
       },900); 
      } 
     }); 
    }); 
    </script> 
</head> 
<body style="height: 1500px;"> 

<div style="width: 400px; height: 50px; position: absolute; top: 500px; background-color: silver; opacity: 0.0;" class="hideme">asdsa</div> 

</body> 
</html> 

我已经改变了功能咯,希望你会知道该怎么做;)

0

哦,亲爱的.. :)固定

如果($(窗口).scrollTop()> 1200){

需要从窗口中设置不.hideme DIV($此)

+0

该死的,你打败了我! –

+0

哈哈:),我怎么会得到它淡入淡出时,它滚动备份? – Brent

+0

添加了答案! –