//调用方式
// jiazai({
//     page: 2,  //默认1可不传
//     url: "/s.html?{:http_build_query($get)}",  
//     ok: function(res){
//         if(res.code==1){
//             var row=res.data.data
//             var html="";
//             for (var i = 0; i < row.length; i++) {
//                 html+='<div class="xq-mod">\
//                             <a href="show.html?id='+row[i].id+'" class="title">'+row[i].title+'</a>\
//                             <div class="smtit">\
//                                 来源:'+row[i].qihao.zazhi+':'+row[i].qihao.name+'卷\
//                             </div>\
//                             <div class="txt">'+row[i].content+'</div>\
//                         </div>'
//             }
//             $("#list").append(html);
//         }
//     },  
//     lastpage:function(res) {
//         return res.data.last_page; //返回末页页码
//     }
// })


var isloading = false;
function jiazai(options){
    var defaults = {  
        page: 1,  
        url: "",  
        ok: function(res){}, 
        lastpage:function(res){},  
    }; 
    var con = $.extend({}, defaults, options);  

    $(window).bind("scroll", function () {
        // console.log("-----------"); div滚动的写法
        // console.log($(".idx-w").scrollTop());div外框
        // console.log($(".idx-w").height()); div外框
        // console.log($('.splist').height()); 内容区域
        // if ($(".idx-w").scrollTop() + $(".idx-w").height() > $('.splist').height() - 230 &&  !isloading) {

        if ($(document).scrollTop() + $(window).height() > $(document).height() - 10 && !isloading) {
          isloading = true;
          getMore(con);
        }
    });
    if($(document).height()<=$(window).height()){
        getMore(con)
    }
}

function getMore(con) {
    var url = con.url +  (con.url.includes('?') ? '&' : '?') +"page=" + con.page;
    console.log("加载第一页")
    $.getJSON(url, function (res) { 
        con.ok(res)
        if(con.lastpage(res)>con.page){
             isloading = false;
        }else{
            console.log("已是最后一页")
        }
        con.page++;
    })
}


点赞(0)

评论列表 共有 0 条评论

暂无评论
立即
投稿
发表
评论
返回
顶部