JS下拉自动加载
导入jquery.mousewheel.js
定义url=路径
JS
1 $(function(){ 2 /* 3 * 滑动加载 4 * */ 5 var page = 1; 6 var end = 0; //1代表全部加载完毕 7 var plist = $('.product-list'); 8 function getData(){ 9 notice.text('正在加载···'); 10 $.ajax({ 11 async : true, 12 type : 'post', 13 url : url, 14 data : {'page':page,'bid':bid,}, 15 dataType: 'json', 16 success : function(msg){ 17 if(msg.status==1){ 18 page=msg.next; 19 if(msg.end==1){ 20 end=1; 21 } 22 for(var r=0;r<msg.result.length;r++){ 23 console.log(msg.result[0].title); 24 str='<li><a class="back block" title="'+msg.result[r].title+'" href="'+link+msg.result[r].id+'" style="background-image :url('+rt+msg.result[r].img+')"></a></li>'; 25 plist.append(str); 26 } 27 28 } 29 console.log(msg.info); //调试 30 }, 31 error : function(){ 32 console.log('网络出现故障!'); 33 } 34 }); 35 } 36 getData(); //初始化一页数据 37 $('body').mousewheel(function(event) { 38 if(end!=1&&($('body').scrollTop()>(plist.offset().top+plist.height()-$(window).height()-200))){ 39 getData(); 40 } 41 console.log($('body').scrollTop()); 42 console.log(plist.offset().top+plist.height()); 43 }); 44 });
AJAX数据 (PHP)
function ajaxList(){ if(!IS_POST){ $data['status'] = 0; $data['info'] = '非法请求'; $this->ajaxReturn($data,'JSON'); }else{ $page = intval($_POST['page']); //当前页码 $bid = intval($_POST['bid']); //类别 0为所有 if($bid){ $where['bid']=$bid; } $number = 6; //每次请求的数量 $count = M('Product')->where($where)->count(); //总数量 $pageCount = ceil($count/$number); //总页数 /* 开始请求 */ if($page>$pageCount){ $data['status'] = 0; $data['info'] = '没有更多的新片了'; $this->ajaxReturn($data,'JSON'); }else{ $sql = M('Product'); $result = $sql->where($where)->order('sort desc,id desc')->limit(($number*($page-1)).','.$number)->select(); $data['status'] = 1; $data['result'] = $result; $data['sql'] = $sql->getLastSql(); if($page==$pageCount){ $data['next'] = $page; $data['info'] = '新片已全部加载'; $data['end'] = 1; }else{ $data['next'] = $page+1; $data['info'] = '点击加载更多'; } $this->ajaxReturn($data,'JSON'); } } }