滑到頁面底端自動加載更多

$(document).scrollTop()
獲取垂直滾動的距離,即當前滾動的地方的窗口頂端到整個頁面頂端的距離
$(document).scrollLeft()
這是獲取水平滾動條的距離

要獲取頂端 只需要獲取到scrollTop()==0的時候,就是頂端了
要獲取底端,只要獲取
scrollTop()>=($(document).height()-$(window).height())
就可以知道已經滾動到底端了

$(document).height() 是獲取整個頁面的高度
$(window).height() 是獲取當前 也就是你瀏覽器所能看到的頁面的那部分的高度

<script type="text/javascript">
    $(window).scroll(function(){
        var documentTop = $(document).scrollTop();
        var windowHeight = $(window).height();
        var documentHeight = $(document).height();
        if(documentTop >= (documentHeight-windowHeight)){
           loaddata();
        }    
    })
</script>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章