帝国cms 加载更多升级版
加载更多博主曾经多次折腾最终得出以下两个版本 适用于大多数项目
至于加载更多的gif 图片 请自己找素材吧
JS 调用部分 (栏目设置中 最好显示12条数据 匹配js拉取数据 且不重复 也可以自行设置测试条数)
本例按当前栏目拉取 适合列表页
$(function(){
var i = 1; //设置当前页数
window.onscroll = function(){
var scrollTop = document.body.scrollTop;
var bot = 50; //bot是底部距离的高度
if ((bot + $(window).scrollTop()) >= ($(document).height() - $(window).height())) {
$.ajax({
url : '/e/action/getmore.php',
type:'POST',
data:{"next":i,'table':'news','classid':'[!--self.classid--]','action':'getmorenews','limit':12,'small_length':120},
dataType : 'html',
beforeSend:function(){
$("#loadmore").show().html(' 正在努力加载中...');
$('#loadmore').attr('disabled','disabled');
},
success : function(data){
if(data){
$("#showajaxnews").append(data);
$("#loadmore").removeAttr('disabled');
$("#loadmore").html('下拉加载更多');
i++;
}else{
$("#loadmore").show().html("已全部加载完毕!");
$('#loadmore').attr('disabled','disabled');
return false;
}
}
});
}
}
});
容器和显示按钮 (showajaxnews)
<ul id="showajaxnews">
[!--empirenews.listtemp--]
[!--empirenews.listtemp--]
<a class="go-more" id="loadmore">加载更多
后端数据结构 (/e/action/getmore.php)
<?php
require('../class/connect.php');
require('../class/db_sql.php');
require('../data/dbcache/class.php');
if($_POST[action] == 'getmorenews'){
$table=htmlspecialchars($_POST[table]);
if(empty($_POST[orderby])){$orderby='newstime';}else{ $orderby=htmlspecialchars($_POST[orderby]);}
if(empty($_POST[myorder])){$myorder='desc';}else{ $myorder='asc';}
if(empty($_POST[limit])){$limit=12;}else{ $limit=(int)$_POST[limit];}
if(empty($_POST[classid])){$where=null;}else{ $where='where classid in('.$_POST[classid].')';}
if(empty($_POST[length])){$length=50;}else{ $length=(int)$_POST[length];}
if(empty($_POST[small_length])){$small_length=500;}else{ $small_length=(int)$_POST[small_length];}
$link=db_connect();
$empire=new mysqlquery();
$num =(int)$POST['next'] $limit;
if($table){
$sql=$empire->query("SELECT FROM `".$dbtbpre."ecms".$table."` $where order by $orderby $myorder limit $num,$limit");
while($r=$empire->fetch($sql)){
if($r[mtitlepic]==''){
$r[mtitlepic]=$public_r[news.url]."e/data/images/notimg.gif";
}
$oldtitle=stripSlashes($r[title]);
$title=sub($oldtitle,'',$length);
$smalltext=stripSlashes($r[smalltext]);
$smalltext=sub($smalltext,'',$small_length);
$classname=$class_r[$r[classid]][classname];
$newsurl=$public_r[newsurl];
$classurl=$newsurl.$class_r[$r[classid]][classpath];
$urls = sys_ReturnBqTitleLink($r);
?>
<a href="<?=$urls?>">
<div class="media-image">
<img src="/miss.png"pun"><?=$r[mtitlepic]?>" alt="<?=$r[title]?>" width=60 height=60 />
<div class="media-content">
<h3 class="title"><?=$r[title]?>
<p class="meta">
<span class="meta-time"><?=date("Y-m-d",$r[newstime])?>
<?php
}
}
}
db_close();
$empire=null;
?>
另一个版本 点击后再拉取数据 适合首页等部位按制定栏目拉取
$(function(){
var i = 1; //设置当前页数
$('#loadmore').click(function(){
$.ajax({
url : 'http://m.zhaohuati.com/e/action/getmore.php',
type:'POST',
data:{"next":i,'table':'news','classid':'14','action':'getmorenews','limit':12,'small_length':120},
dataType : 'html',
beforeSend:function(){
$("#loadmore").show().html('<img src="/images/loaduai.gif" width=23/> 正在努力加载中...');
$('#loadmore').attr('disabled','disabled');
},
success : function(data){
if(data){
$("#showajaxnews").append(data);
$("#loadmore").removeAttr('disabled');
$("#loadmore").html('点击加载更多');
i++;
}else{
$("#loadmore").show().html("已全部加载完毕!");
$('#loadmore').attr('disabled','disabled');
return false;
}
}
});
});
});
注意: