瀏覽器滾動條到底部自動加載更多


代碼如下

$(window).on('scroll',function(){
    /*console.log("scrollTop--->" + scrollTop());
    console.log("windowHeight--->" + windowHeight());
    console.log("documentHeight--->" + documentHeight());*/
    if(scrollTop() + windowHeight() >= documentHeight()){
        loadMore();
    }
});
function loadMore() {
    console.log("enter load More , isloading = " + isloading);


}
function scrollTop(){
    return Math.max(
            //chrome
            document.body.scrollTop,
            //firefox/IE
            document.documentElement.scrollTop);
}
function documentHeight(){
    //現代瀏覽器(IE9+和其他瀏覽器)和IE8的document.body.scrollHeight和document.documentElement.scrollHeight都可以
    return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
}
function windowHeight(){
    return (document.compatMode == "CSS1Compat")?
            document.documentElement.clientHeight:
            document.body.clientHeight;
}


免責聲明!

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



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