首先调用20条默认的信息,代码如下
<section class="FConBig"> <div class="divcon"> <div id="divcon1"> [e:loop={"select * from www_11px_cn_ecms_news where classid in (2,3,4,5,6) order by newstime desc limit 20",6,24,0}] <dl class="FConSmall"> <dt><a href="<?=$bqsr['titleurl']?>"><img src="<?=$public_r['add_www_11px_cn_url']?><?=$bqr['titlepic']?>" width="100%"></a></dt> <dd> <a href="<?=$bqsr['titleurl']?>" class="FConWza"> <span class="FConWzTag"><?=$bqsr[classname]?></span> <span class="FConTimeIco"></span> <span class="FConWzTime"><?=date('Y-m-d',$bqr[newstime])?></span> </a> <a href="<?=$bqsr['titleurl']?>" class="FConWzDesc"><?=$bqr['title']?></a> </dd> </dl> [/e:loop] </div> </div> </section> <div class="FConBig" id="paiList"></div> <div id="divcon2"><div id="divload"></div></div>
然后再是下拉加载的JS代码,
<script src="/Style/js/jquery-1.7.1.min.js"></script> <script language="javascript" type="text/javascript"> $(document).ready(function(){ var page = 1;//这个不是真正的页数,而是位移量 var nextpage = 1; var wan=true; var totalheight = 0; function loadData(){ totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop()); if ($(document).height() <= totalheight && wan==true) { // 说明滚动条已达底部 var cid = 0; page = nextpage; $.ajax({ url : '/Style/getajax.php', type:'get', data:{"classid":cid,'next':page}, dataType : 'html', beforeSend:function(){ $('#divload').html('<div id="pullUp"><p class="pullUpLabela"><img src="/Style/css/img/wait1.gif" width="20"><span>正在载入</span></p></div>'); $('#divcon2').show(); wan=false; }, success : function(str){ if(str!=""){ $('#divcon1').show(); $('#divcon2').hide(); $('#divcon1').append(str); nextpage++; wan=true; }else{ $('#divload').html('<div id="pullUp"> <span class="pullUpLabel">加载完毕!</span></div>'); $('#divcon2').show(); } } }); }} $(window).scroll( function() { loadData(); }); }) </script>
最后就是getAJAX.php的加载代码
<?php $ye=strFilter($_GET["next"]); $clasid=strFilter($_GET["classid"]); if($clasid==1){$clasid="2,3,4,5,6";} if($clasid==7){$clasid="8,9,10,11,12,13";} if($clasid==14){$clasid="15,16,17";} if($clasid==18){$clasid="19,20,21,22";} if($clasid==23){$clasid="24,25,26,27,38";} if($clasid==28){$clasid="29,30,31,32";} if($clasid==33){$clasid="34,35,36,37";} if($clasid==0){ $aabbccdd = base64_encode("select * from www_11px_cn_ecms_news order by newstime desc limit"); }else{ $aabbccdd = base64_encode("select * from www_11px_cn_ecms_news where classid in ($clasid) order by newstime desc limit"); } function strFilter($str){ $str = str_replace('`', '', $str); $str = str_replace('·', '', $str); $str = str_replace('~', '', $str); $str = str_replace('!', '', $str); $str = str_replace('!', '', $str); $str = str_replace('@', '', $str); $str = str_replace('#', '', $str); $str = str_replace('$', '', $str); $str = str_replace('¥', '', $str); $str = str_replace('%', '', $str); $str = str_replace('^', '', $str); $str = str_replace('……', '', $str); $str = str_replace('&', '', $str); $str = str_replace('*', '', $str); $str = str_replace('(', '', $str); $str = str_replace(')', '', $str); $str = str_replace('(', '', $str); $str = str_replace(')', '', $str); $str = str_replace('-', '', $str); $str = str_replace('_', '', $str); $str = str_replace('——', '', $str); $str = str_replace('+', '', $str); $str = str_replace('=', '', $str); $str = str_replace('|', '', $str); $str = str_replace('', '', $str); $str = str_replace('[', '', $str); $str = str_replace(']', '', $str); $str = str_replace('【', '', $str); $str = str_replace('】', '', $str); $str = str_replace('{', '', $str); $str = str_replace('}', '', $str); $str = str_replace(';', '', $str); $str = str_replace(';', '', $str); $str = str_replace(':', '', $str); $str = str_replace(':', '', $str); $str = str_replace(''', '', $str); $str = str_replace('"', '', $str); $str = str_replace('“', '', $str); $str = str_replace('”', '', $str); $str = str_replace(',', '', $str); $str = str_replace(',', '', $str); $str = str_replace('<', '', $str); $str = str_replace('>', '', $str); $str = str_replace('《', '', $str); $str = str_replace('》', '', $str); $str = str_replace('.', '', $str); $str = str_replace('。', '', $str); $str = str_replace('/', '', $str); $str = str_replace('、', '', $str); $str = str_replace('?', '', $str); $str = str_replace('?', '', $str); return trim($str); } require("../e/class/connect.php"); if(!defined('InEmpireCMS')) { exit(); } require("../e/class/db_sql.php"); require("../e/class/q_functions.php"); $link=db_connect(); $empire=new mysqlquery(); $yema= $ye*20; $query = @mysql_query(base64_decode($aabbccdd)." $yema,20") //执行SQL语句 or die("SQL语句执行失败2"); while($rs = mysql_fetch_assoc($query)){ $src = $rs[id]; $xwclassid=$rs['classid']; $xwtitle=$rs['title']; $xwtitleurl=$rs['titleurl']; $xwtitlepic=$rs['titlepic']; $smalltext=$rs['smalltext']; $newstime=$rs['newstime']; $onclick=$rs['onclick']; $tuurl=$public_r[add_www_11px_cn_url]; $queryss = @mysql_query("select * from www_11px_cn_enewsclass where classid='$xwclassid'") //执行SQL语句 or die("SQL语句执行失败3"); while($rstt = mysql_fetch_assoc($queryss)){$xwclassname=$rstt[classname];$xwclasspath=$rstt[classpath];} ?> <dl class="FConSmall"> <dt><a href="<?=$xwtitleurl?>"><img src="<?=$tuurl?><?=$xwtitlepic?>" width="100%"></a></dt> <dd> <a href="<?=$xwtitleurl?>" class="FConWza"> <span class="FConWzTag"><?=$xwclassname?></span> <span class="FConTimeIco"></span> <span class="FConWzTime"><?=date('Y-m-d',$newstime)?></span> </a> <a href="<?=$xwtitleurl?>" class="FConWzDesc"><?=$xwtitle?></a> </dd> </dl> <?php } ?>
这段代码加了写判断栏目的功能,大家按格式自行修改吧。
资源均来自第三方,谨慎下载,前往第三方网站下载