页面滚动条翻页

来源:互联网 发布:苏州海默淘宝开店培训 编辑:程序博客网 时间:2024/05/21 12:46
function getWindowHeight() {
    var windowHeight = 0;    if (document.compatMode == "CSS1Compat") {
        windowHeight = document.documentElement.clientHeight;
    } else {
        windowHeight = document.body.clientHeight;
    }
    return windowHeight;
}
//滚动条滚动高度
function getScrollHeight() {
    var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
    if (document.body) {
        bodyScrollHeight = document.body.scrollHeight;
    }
    if (document.documentElement) {
        documentScrollHeight = document.documentElement.scrollHeight;
    }
    scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;    return scrollHeight;
}
//文档高度
function getDocumentTop() {
    var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
    if (document.body) {
        bodyScrollTop = document.body.scrollTop;
    }
    if (document.documentElement) {
        documentScrollTop = document.documentElement.scrollTop;
    }
    scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;    return scrollTop;
}


var p = 1 ;  
window.onscroll = function () { 
    //监听事件内容
    if(getScrollHeight() == getWindowHeight() + getDocumentTop()){
    str = "";
        //当滚动条到底时,这里是触发内容
        //异步请求数据,局部刷新dom  
        //if(tag==1) return false;
        p++;   
  fyurl = "请求翻页的接口地址?p="+p; //p为当前页数
        $.ajax({url:fyurl,type : "get",async : false,dataType:"json", success :function(data){
        //追加下页内容
  })
    }
0 0
原创粉丝点击