2012-03-14 75 views
6

一旦它觸及底部,然後有一個回調函數?如何使用JQuery檢測用戶是否滾動到頁面的底部?

+0

http://stackoverflow.com/questions/3962558/javascript-detect-scroll-end – 2012-03-14 07:50:53

+1

檢查這個http://stackoverflow.com/questions/3962558/javascript-detect-scroll-end – Gopesh 2012-03-14 07:57:47

+0

[如何檢查用戶是否滾動到底部]的可能重複(http://stackoverflow.com/questions/3898130/how-to-check-if-a-user-has-scrolled-to-the-底部) – csharpfolk 2014-05-03 06:45:26

回答

25

可以以這種方式使用.scroll()事件的窗口:

$(window).scroll(function() { 
    if($(window).scrollTop() + $(window).height() == $(document).height()) { 
     alert("bottom!"); 
    } 
}); 

檢查live demo

到如果用戶是3/4下來的頁面,您可以試試這個

檢測
$(window).scroll(function() { 
    if($(window).scrollTop() + $(window).height() > $(document).height() - .75*$(document).height()) { 
     alert("3/4th of bottom!"); 
    } 
}); 
+0

通常它的工作,但與「警惕」它崩潰我的法郎,它從字面上「變黑」。但我用console.log進行了測試,它工作正常。 – devnull69 2012-03-14 07:57:33

+0

謝謝。這工作!如果我想檢測用戶是否在頁面上3/4,該怎麼辦? – TIMEX 2012-03-14 08:15:14

+7

我認爲你在頁面3/4下的解決方案實際上是在尋找「從頁面底部開始的75像素」。將'$(document).height() - 75'改爲'$(document).height()* 0.75'應該有效。 – sffc 2013-07-25 10:23:45