首页 > 代码库 > 滚动加载更多

滚动加载更多

/**
 * 异步加载更多
 * create by tujia @2016.10.19
 */
function load_more(id,no_more){
    var _id         = id || ‘lists‘;
    var _no_more     = no_more || ‘<li style="line-height: 4rem; text-align: center; font-size: 1rem; color: #717171;">没有更多啦</li>‘;

    var dH = 0,wH = 0,page_no = 1,can_loading = true;
    $(document).ready(function(){
        dH = $(document).height();
        wH = $(window).height();
    });
    $(window).scroll(function(){
        var offset_top = $(this).scrollTop();

        if(can_loading==true && (dH-offset_top-wH)<100){
            can_loading = false;
            $.get(‘‘, {‘is_ajax‘:1, ‘page_no‘:++page_no}, function(res){
                if(res!=‘‘){
                    $(‘#‘+_id).append(res);
                    dH         = $(document).height();
                    can_loading = true;
                }else{
                    $(‘#‘+_id).append(_no_more);
                }
            }, ‘html‘);
        }
    });
}

 

滚动加载更多