(一)js代码如下
var currentPage =1;
var pages = {:$pageNum:};
function nextPage(){
if (pages == 0){
return;
}
currentPage++;
if(currentPage>pages){
jQuery('#no_more').show();
return;
}
if(currentPage>1){
jQuery('.loading').show();
}
var response = $.ajax({
type: "POST",
url: "/index.php?m=home&c=yoga&a=yogaAjax",
data: {
"page" : currentPage,
},
success: function(data){
jQuery('.fishing-list').append(data);
jQuery('.loading').hide();
},
async: true
});
}
//滚动时加载数据
$(window).scroll(function(){
if (getScrollTop() + getClientHeight() >= getScrollHeight()){
nextPage();
}
});
//获取滚动条当前的位置
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);
}
(二)PHP代码处理
//关注的瑜伽馆的列表
public function yogaAjax(){
$pagesize = 5;
$page = \Yin::_input('request.page',1);
$id = isset($_REQUEST['id']) ? (int)Yin::_input('request.id') : '';
if(!intval($page)){
$page =1;
}
$limit = ($page-1)*$pagesize;
$limit.=",".$pagesize;
$list = $this->yoga_favourite->getView("`userId`=".$this->member_id,$limit,$order='id desc');
$info = array();
if(!empty($list)){
foreach($list as $key=>$val){
$info[] = $this->yoga->getYogaById($val['yogaId'],'`id`,`name`,`address`,`thumb`,`avgscore`');
$info[$key]['create'] = $val['created'];
}
}
$httpRequestTools = \Yin::load_sys_class('HttpRequest');
if(!$info){
if($httpRequestTools->isAjax()){
echo "";
exit;
}else{
return "";
}
}
$html = \Yin::template('home','yoga_ajax_list','default',true,array("info"=>$info));
if($httpRequestTools->isAjax()){
echo $html;
exit;
}else{
return $html;
}
}