2013-04-17 73 views
-2

我搜索了問題,但未找到對特定問題的答案:如何在用戶滾動特定距離時隱藏元素。我似乎無法將我的頭圍繞在邏輯上。當用戶滾動特定距離時隱藏元素

我想做什麼:

$(window).scroll(function(){ 
    if (document has been scrolled 250px or -250px) { 
     $("#box").hide(); 
    } 
}); 

任何幫助,將不勝感激。謝謝。

+1

可能重複[如何使用jQuery來隱藏DIV然後消除它在滾動瀏覽文檔?](http://stackoverflow.com/questions/14584666/how-to -use-jquery-to-hide-div-then-fade-in-on-document-scroll) – Jai

+0

否定。不是該問題的重複。 –

+1

一個更接近的重複將[當一定量的滾動發生時隱藏一個元素](http://stackoverflow.com/q/6820769/584192) –

回答

0

this is demo

$(window).scroll(function() { 
if ($(this).scrollTop() > 250) { 
    $("#box").css({ 
     'display': 'none' 
    }); 
} 
}); 
+0

'scrollTop()'的$(this).scrollTop()> -250'最小值爲'0'並且您的條件正在注意。它會在所有情況下返回「true」 – Ejaz

+0

謝謝,我會試一試。 – MCM

0
$(window).bind('scroll', function(){ 
    if($(this).scrollTop() > 200) { 
     $("#box").hide(); 
    } 
});