2012-08-30 101 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

添加了答案! –