var alt=$(alt_id);/**/ var box=$(box_id);/**/ var temp=$(tmp_id);/**/ var temphtml=temp.html();/*//console.log(temphtml);*/ //temp.hide(); var nowpage=1;/*当前页码*/ var isend=0;/*是否发送请求 0表示可以发送请求 1表示不能发送请求*/ var where='';/*表示请求的条件*/ try { if(typeof bwhere!="undefined") { where=bwhere; } } catch(e) {} console.log(where); function getScrollTop() { var scrollTop = 0; if (document.documentElement && document.documentElement.scrollTop) { scrollTop = document.documentElement.scrollTop; } else if (document.body){scrollTop = document.body.scrollTop; } return scrollTop; } function getClientHeight() { var clientHeight = 0;if (document.body.clientHeight && document.documentElement.clientHeight) {clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight); } else {clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);} return clientHeight; } function getScrollHeight(){return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);} /*vue mounted 绑定后完成后事件*/ function load1() { var box2=$(tmp_id); var html=box2.html();/*获取新的数据*/ console.log(box_id); box.append(html);/*新数据填充到填充对象*/ console.log(html); box2.html(temphtml);/*更新 vue 模板初始化代码*/ } /*vue模板绑定事件 注意属性的解析要用: 比如 */ function vueload(data) { var demo2 = new Vue({ el:tmp_id,data:{items: data},mounted:function(){load1();} }) } /*滚动事件绑定下拉加载方法*/ window.onscroll=function() { //return false; var footheight=1250; var height1=getScrollTop()+getClientHeight(); var height2=getScrollHeight()-footheight; if (height1>=height2) { if (isend==0){nowpage++;var addhtml=autoload(nowpage);} } } //alt.hide(); alt.click(function(){ if (isend==0){nowpage++;var addhtml=autoload(nowpage);} }); /*div滚动到底部时间*/ var distanceScrollCount = 0; //滚动距离总长 var distanceScroll = 0; //滚动到的当前位置 var divHight = $("body").height(); $("body,#app").scroll(function(){ console.log('scroll'); distanceScrollCount = $(this)[0].scrollHeight; distanceScroll = $(this)[0].scrollTop; if(distanceScroll + divHight >= distanceScrollCount-1800) { if (isend==0){nowpage++;var addhtml=autoload(nowpage);} } }); /*下拉加载执行的方法 参数p表当前的页面*/ function autoload(p) { alt.html('加载中...'); isend=1; $.ajax({ type:"POST",dataType:'json',url:posturl,data:where+"&p="+p, success:function(msg2){ console.log(msg2); layer.msg('加载中...',{time:400}); msg=JSON.parse(msg2); box.attr('page',p); msg.status=parseInt(msg.status); msg.datanum=parseInt(msg.datanum); switch (msg.status) { /*请求成功*/ case 1: switch (msg.datanum) { case 1: /*有数据*/ var datas=msg.data; /*console.log(datas);*/ /*vue 加载数据 然后填充到填充的对象里 datas数组举例 datas=[{ message: 'Foo' },{ message: 'Bar' }]; */ vueload(datas); console.log('page:'+p); if (msg.message=='ok') { isend=0; alt.show().html('已经到底啦~').hide(); //layer.msg('已全部加载完成'); } else { isend=0; //alt.html('点击加载更多'); } break; default: alt.show().html('已经到底啦~').hide(); layer.msg('已全部加载完成'); break; } break; default: console.log('error:'+status); layer.msg(msg.message); break; } },error:function(){ alt.html('网络错误');layer.msg('网络错误'); } }); } /*初始化加载第一页*/ //autoload(nowpage); // // ///*layer.msg('aaaaaaa',{time:5000});*/