JavaScript手機端頁面滑動到底部加載信息(移動端ajax分頁)


//獲取窗口可視范圍的高度
function getClientHeight(){   
    var clientHeight=0;   
    if(document.body.clientHeight&&document.documentElement.clientHeight){   
         clientHeight=(document.body.clientHeight<document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;           
    }else{   
         clientHeight=(document.body.clientHeight>document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;       
    }   
    return clientHeight;   
}

function getScrollTop(){   
    var scrollTop=0;   
    scrollTop=(document.body.scrollTop>document.documentElement.scrollTop)?document.body.scrollTop:document.documentElement.scrollTop;           
    return scrollTop;   
}
//滾動加載
function scrollLoad(){
    //可視窗口的高度
    var scrollTop = 0;
    var scrollBottom = 0;
    $(document).scroll(function(){
        var dch = getClientHeight();
        scrollTop = getScrollTop();
          scrollBottom = document.body.scrollHeight - scrollTop;
          if(scrollBottom >= dch && scrollBottom <= (dch+10)){              
              if(pageCount == (currentPage+1)){
                      $(".click-load").hide();
                      return;
                  }              
                currentPage++;
                showList(currentPage,pageSize);                
            }
    });
}

順便寫一下常用的高度:

Javascript:

alert(document.body.clientWidth);        //網頁可見區域寬(body)

alert(document.body.clientHeight);       //網頁可見區域高(body)

alert(document.body.offsetWidth);       //網頁可見區域寬(body),包括border、margin等

alert(document.body.offsetHeight);      //網頁可見區域寬(body),包括border、margin等

alert(document.body.scrollWidth);        //網頁正文全文寬,包括有滾動條時的未見區域

alert(document.body.scrollHeight);       //網頁正文全文高,包括有滾動條時的未見區域

alert(document.body.scrollTop);           //網頁被卷去的Top(滾動條)

alert(document.body.scrollLeft);           //網頁被卷去的Left(滾動條)

alert(window.screenTop);                     //瀏覽器距離Top

alert(window.screenLeft);                     //瀏覽器距離Left

alert(window.screen.height);                //屏幕分辨率的高

alert(window.screen.width);                 //屏幕分辨率的寬

alert(window.screen.availHeight);          //屏幕可用工作區的高

alert(window.screen.availWidth);           //屏幕可用工作區的寬

Jquery

alert($(window).height());                           //瀏覽器當前窗口可視區域高度

alert($(document).height());                        //瀏覽器當前窗口文檔的高度

alert($(document.body).height());                //瀏覽器當前窗口文檔body的高度

alert($(document.body).outerHeight(true));  //瀏覽器當前窗口文檔body的總高度 包括border padding margin

alert($(window).width());                            //瀏覽器當前窗口可視區域寬度

alert($(document).width());                        //瀏覽器當前窗口文檔對象寬度

alert($(document.body).width());                //瀏覽器當前窗口文檔body的寬度

alert($(document.body).outerWidth(true));  //瀏覽器當前窗口文檔body的總寬度 包括border padding margin

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM