//当前页
var currentPage = 1;
//总页数
var totalPage = 0;
var pageSize = 50;
pageSize: pageSize, //每页的记录行数(*)
responseHandler: function(res) {
// 处理后端返回的数据
$("#c-total").html(res.total);
totalPage = Math.ceil(res.total/pageSize);
// 返回处理后的数据
return {
total: res.total,
rows: res.rows
};
},
onLoadSuccess: function () {
//瀑布流加载
//标识位
var isTrue = true;
var nDivHight = $(".fixed-table-body").height();
console.log('总页数:'+totalPage);
$(window).scroll(function () {
//console.log('滚动触发');
var nScrollHight = 0; //滚动距离总长(注意不是滚动条的长度)
var nScrollTop = 0; //滚动到的当前位置
var nDivHight = $(".fixed-table-body").height(); //初始table高度
//nScrollHight = $(this)[0].scrollHeight;
// nScrollTop = $(window).scrollTop();
// var maxHight = $("#main").height();
// var flagHeight = Math.ceil(nScrollTop + nDivHight);
//小于总页数加载下一页
if (currentPage < totalPage){
//滚动条到底部自动加载下一页
if($(document).scrollTop() >= $(document).height() - $(window).height() - 500){
console.log('到底部触发');
if (isTrue){
setTimeout(function () {
getList();
currentPage++;
},1000);
//杀死标识位,阻止多次请求
isTrue = false;
}
}
}
});
function getList() {
$.ajax({
url: 'rental/index'+ location.search,
method: 'get',
dataType: 'json',
data: {
offset: currentPage*pageSize,
limit:pageSize,
sort:'id',
order:'desc'
},
beforeSend: function () {
close = layer.load(1);
},
success:function (data) {
$("#table").bootstrapTable("append",data.rows);
layer.close(close);
isTrue = true;
}
})
}
},