<script type="text/javascript">
var loadConfig = {
url_api:'url',
typeid:0,
page:2,
pagesize:10, //和初始显示一致
loading : 0,
}
function loadMoreApply(){
$('.moregif').show().delay();
if(loadConfig.loading == 0){
var typeid = loadConfig.typeid;
var page = loadConfig.page;
var pagesize = loadConfig.pagesize;
var url = loadConfig.url_api,data={ajax:'pullload',typeid:typeid,page:page,pagesize:pagesize};
function ajax(url, data) {
$.ajax({url: url,data:data,async: false,type: 'GET',dataType: 'json',success: function(data) {
addContent(data);
$('.moregif').hide();
}});
}
ajax(url,data);
}
}
function addContent (rs){
if(rs.statu== 1){
var data = rs.list;
var total = rs.total; //13
var arr=[];
var len = data.length;
for(var i=0;i<len;i++){
arr.push('<li class="am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left arc-list">');
arr.push('<div class="am-u-sm-4 am-list-thumb"><a href="'+data[i].arcurl+'" > <img src="'+data[i].picname+'"</a></div>');
arr.push('<div class="am-u-sm-8 am-list-main">');
arr.push('<h3 class="am-list-item-hd"><a href="'+data[i].arcurl+'" >'+data[i].title+'</a></h3>');
arr.push('<p class="pubdata"><span>'+data[i].stime+'</span></p>');
arr.push('</div>');
arr.push('</li>');
}
$('#cms_list').append(arr.join(''));
loadConfig.load_num = rs.load_num;
// alert(loadConfig.load_num);
if(total<loadConfig.page*loadConfig.pagesize || loadConfig.page > loadConfig.load_num){
alert("暂无数据");
document.getElementById("loadlist").removeEventListener('click',loadMoreApply,false);
}
loadConfig.page++;
loadConfig.loading = 0;
}
}
/*function pullLoad(){
document.getElementById("loadlist").addEventListener('click', loadMoreApply, false);
}
pullLoad();*/
$(window).scroll(function(){
//获取当前文档的高度
var docHeight = $(document).height();
//获取当前滚动条的高度
var scrollTop = $(this).scrollTop();
//获取当前可视区的高度
var height = $(this).height();
if((docHeight-scrollTop-height)<=20){
loadMoreApply();
}
});
window.onbeforeunload = function () {
var scrollPos;
if (typeof window.pageYOffset != 'undefined') {
scrollPos = window.pageYOffset;
}
else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
scrollPos = document.documentElement.scrollTop;
}
else if (typeof document.body != 'undefined') {
scrollPos = document.body.scrollTop;
}
document.cookie = "scrollTop=" + scrollPos; //存储滚动条位置到cookies中
}
window.onload = function () {
if (document.cookie.match(/scrollTop=([^;]+)(;|$)/) != null) {
var arr = document.cookie.match(/scrollTop=([^;]+)(;|$)/); //cookies中不为空,则读取滚动条位置
document.documentElement.scrollTop = parseInt(arr[1]);
document.body.scrollTop = parseInt(arr[1]);
}
}
</script>
来源:https://www.cnblogs.com/yewook/p/7402820.html