帝国CMS无限加载是借鉴别的CMS插件更改的,现在还在制作样式中,完成后会以插件分享给大家.
无限加载常见的原理是利用PHP文件调用数据库信息,在用JS读取PHP信息,最后插入显示到页面.
PHP文件代码:
<?php
require_once('../../e/class/connect.php'); //引入数据库配置文件和公共函数文件
require('../../e/class/db_sql.php'); //引入数据库操作文件
$link=db_connect(); //连接MYSQL
$empire=new mysqlquery(); //声明数据库操作类
$editor=1; //声明目录层次
$last = $_POST['last'];
$amount = $_POST['amount'];
$user = array('demo1','demo2','demo3','demo3','demo4');
$sql=$empire->query("select * from ceshi_ecms_news order by id desc limit $last,$amount");
while ($row=$empire->fetch($sql)) {
$addurl="<a href=".$row['titleurl'].">".$row['title']."</a>";
$sayList[] = array(
'content'=>$row['username'],
'author'=>$addurl,
'url'=>$row['titleurl'],
'date'=>date('m-d H:i',$row['newstime'])
);//开源软件:Cuoxin.com
}
echo json_encode($sayList);
db_close(); //关闭MYSQL链接
$empire=null; //注消操作类变量
?>
var methods = {
init : function(options){
return this.each(function(){
if(options){
$.extend(settings, options);
}
template = $(this).children(settings.template).wrap('<div/>').parent();
template.css('display','none')
$(this).append('<div class="more_loader_spinner">'+settings.spinner_code+'</div>')
$(this).children(settings.template).remove()
target = $(this);
if(settings.scroll == 'false'){
$(this).find(settings.trigger).bind('click.more',methods.get_data);
$(this).more('get_data');
}
else{
if($(this).height() <= $(this).attr('scrollHeight')){
target.more('get_data',settings.amount*2);
}
$(this).bind('scroll.more',methods.check_scroll);
}
})
},
check_scroll : function(){
if((target.scrollTop()+target.height()+parseInt(settings.offset)) >= target.attr('scrollHeight') && lock == false){
target.more('get_data');
}
},
debug : function(){
var debug_string = '';
$.each(variables, function(k,v){
debug_string += k+' : '+v+'/n';
})
alert(debug_string);
},
remove : function(){
target.children(settings.trigger).unbind('.more');
target.unbind('.more')
target.children(settings.trigger).remove();
},
add_elements : function(data){
//alert('adding elements')
var root = target
// alert(root.attr('id'))
var counter = 0;
if(data){
$(data).each(function(){
counter++
var t = template
$.each(this, function(key, value){
if(t.find('.'+key)) t.find('.'+key).html(value);
})
//t.attr('id', 'more_element_'+ (variables.last++))
if(settings.scroll == 'true'){
// root.append(t.html())
root.children('.more_loader_spinner').before(t.html())
}else{
// alert('...')
root.children(settings.trigger).before(t.html())
}
root.children(settings.template+':last').attr('id', 'more_element_'+ ((variables.last++)+1))
})
}
else methods.remove()
target.children('.more_loader_spinner').css('display','none');
if(counter < settings.amount) methods.remove()
大型站长资讯类网站! https://www.0817zz.com