第一步骤:
粘贴以下代码放置新建get_news_index.php上并上传到 /e/action:
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=3;}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=120;}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[titlepic]==''){
$r[titlepic]=$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];
?>
class="text-muted"> =$r[imgcount]?>
=$r[username]?> 发布于 =date('Y-m-d',$r[newstime])?>
class="focus">
class="thumbnail">
/>
=$smalltext?>...
阅读(=$r[onclick]?>)
class="post-comments">评论(=$r[plnum]?>)
href="JavaScript:makeRequest('=$public_r[news.url]?>e/public/digg?classid==$r[classid]?>&id==$r[id]?>&dotop=1&doajax=1&ajaxarea=diggnum=$r[id]?>','EchoReturnedText','GET','');"
class="post-like" > 赞 (
=$r[diggtop]?> )
class="post-tags">标签:
href="/337/e/tags/?tagname==stripSlashes($r[keyboard])?>"
target="_blank" rel="tag"
data-original-title>=stripSlashes($r[keyboard])?>
//这部分代码是将来列表的样子,可以自己修改自己想要模样
}
}
}
db_close();
$empire=null;
?>
第二步骤:
引入js代码可在自己的服务器下也可以引入远程的。我引的是远程的
我采用的是栏目新建静态页面方式做的。
[!--pagetitle--]
.xs-name {
font-size: 16px !important;
color: #666 !important;
margin: 10px 0;
}
.mui-table-view-cell>a:not(.mui-btn) {
white-space: normal;
text-align: left;
}
.mui-table-view .mui-media-object {
max-width: 60px !important;
height: 49px !important
}
.classimg img {
width: 100%
}
.mui-card {
border-radius: 8px;
margin: 16px 20px;
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.2);
}
.mui-card-content-inner {
padding: 10px 16px 6px 16px
}
$(function() {
var i =0; //设置当前页数
if (!NeuF) var NeuF = {};
NeuF.ScrollPage = function (obj, options, callback) {
var _defaultOptions = {delay: 500, marginBottom: 200}; //默认配置:延迟时间delay和滚动条距离底部距离marginBottom
options = $.extend(_defaultOptions, options);
this.isScrolling = false; //是否在滚动
this.oriPos = 0; //原始位置
this.curPos = 0; //当前位置
var me = this; //顶层
var $obj = (typeof obj == "string") ? $("#" + obj) : $(obj);
//绑定滚动事件
$obj.scroll(function (ev) {
me.curPos = $obj.scrollTop();
if ($(window).height() + $(window).scrollTop() >= $(document.body).height() - options.marginBottom) {
if (me.isScrolling == true) return;
me.isScrolling = true;
setTimeout(function () {
me.isScrolling = false;
}, options.delay); //重复触发间隔毫秒
if (typeof callback == "function") callback.call(null, me.curPos - me.oriPos);
}
;
me.oriPos = me.curPos;
});
};
$(function () {
window.scrollTo(0, 0); //每次F5刷新把滚动条置顶
function show() {
$.ajax({
url: 'http://diguo.bailianyu.com/e/action/get_news_index.php',//自己的域名
type: 'POST',
data: {
"next": i,
'table': 'chengyu',// 这里是我的数据表
'classid':'11',//这里是我id
'action': 'getmorenews',
'limit': 10,
'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("已全部加载完毕!");
console.log(data);
$('#loadmore').attr('disabled', 'disabled');
return false;
}
}
});
};
show();
//marginBottom表示滚动条离底部的距离,0表示滚动到最底部才加载,可以根据需要修改
new NeuF.ScrollPage(window, {delay: 1000, marginBottom: 0}, function (offset) {
if (offset > 0) {
setTimeout(show,1000)
}
});
});
});
滚动加载更多