2016-03-05 56 views
0

我試圖在下面的頁面末尾觸發警報,但只要我滾動,它就會一直觸發。我嘗試了幾種不同的方法,但每次在頁面底部觸發警報。 代碼丟失只是一個數據庫調用,觸發大約20個結果,標題和一個php包含顯示結果。顯示的結果顯示了大約4個屏幕值的數據。JavaScript未在頁面末尾觸發

<body> 
    <div class="maincontainer"> 
     <div class="profilecontainer"> 
      <row> 
       <column cols="4" class="left"> 
        This will have text 
       </column> 
       <column cols="8" class="right"> 
        <ul class="post-column"> 
         <?php 
         foreach ($data as $lineitem): 
         $type = $lineitem['type']; 
         if($type == "article"){ 
          require('php/articleitem.php'); 
         } 

         endforeach; 
         ?> 
        </ul> 
       </column> 
      </row> 
     </div> 
    </div> 

</body> 

</html> 

<script> 
    $(window).scroll(function() { 
     if ($(document).height() <= $(window).scrollTop() + $(window).height()) { 
      alert("End Of The Page"); 
     } 
    }); 
</script> 

回答

0

window.innerHeight + document.body.scrollTop大於或等於document.body.offsetHeight那麼你是在底部

0

不會如預期的$(window).height()結果時,你不必在你的HTML的頂部的文檔類型:

<!DOCTYPE html> 

添加它,你不會再過早地得到警報。

0

我需要設置下面的css值。

.body { 
    position: absolute; 
    min-height: 100%; 
    min-width: 100%; 
} 
+0

使用您在問題中提供的代碼,這不能解決問題。我仍然可以用這個CSS重現你的問題......爲了正確地修復它,你必須定義一個文檔類型,它是[HTML語法中任何文檔的必需部分](https://www.w3)。組織/ TR/HTML的標記/ syntax.html#的doctype,語法) – trincot