2014-11-09 77 views
0

我想實現一個無盡的滾動功能到我的網站,它不工作的原因;這是我的代碼有jquery無盡的滾動不起作用

<script> 
    $(document).ready(function() { 
    alert("This part works"); 
    $(window).scroll(function() { 
     if ($(window).scrollTop() == $(document).height()- $(window).height()) { 
     alert("You have reached the bottom"); 
     } 
    }); 
    }); 
</script> 

第一個警告框的作品,並且讓我知道jQuery是工作,當我滾動至底部或在所有任何建議,第二個警告框不能正常工作?

+1

我剛剛粘貼代碼到控制檯,它的工作在此頁。在您的滾動處理程序中添加console.log以查看它是否到達那裏。 – artm 2014-11-09 06:21:45

+0

你使用什麼瀏覽器? – 2014-11-09 06:27:24

+0

我使用的是Firefox,因爲這是在我的網站上,我試圖確保它適用於所有瀏覽器 – user1591668 2014-11-09 06:40:03

回答

0

試試這個:

$(window).scroll(function (e) { 
     var elem = $(e.currentTarget); 
      if (elem[0].scrollHeight - elem.scrollTop() <= elem.outerHeight()) 
      { 
       alert('You have reached the bottom') 
      } 
    }); 
+0

剛剛嘗試過;它似乎像Firefox也沒有迴應。 – user1591668 2014-11-09 07:34:17

+0

@ user1591668這裏是回答firefox問題:http://stackoverflow.com/questions/15932650/body-scrollheight-doesnt-work-in-firefox – 2014-11-09 07:39:32