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

代碼以下chrome

$(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;
}
相關文章
相關標籤/搜索