国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > CMS > 織夢(mèng)DEDE > 正文

織夢(mèng)dedecms首頁(yè)列表頁(yè)ajax點(diǎn)擊下拉加載更多文章瀑布流效果

2024-07-12 08:47:04
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

織夢(mèng)dedecms實(shí)現(xiàn)點(diǎn)擊下拉加載更多主要用到ajax技術(shù)。具體步驟如下:

一、首先找到并打開(kāi)/plus/list.php文件,在里面找到如下代碼:

require_once(dirname(__FILE__)."/../include/common.inc.php");

在這段代碼下面添加以下代碼:

//列表頁(yè)瀑布流無(wú)限加載代碼if(isset($_GET['ajax'])){    $typeid = isset($_GET['typeid']) ? intval($_GET['typeid']): 0;//傳遞過(guò)來(lái)的分類(lèi)ID    $page = isset($_GET['page']) ? intval($_GET['page']): 0;//頁(yè)碼    $pagesize = isset($_GET['pagesize']) ? intval($_GET['pagesize']): 15;//每頁(yè)多少條,也就是一次加載多少條數(shù)據(jù)    $start = $page>0 ? ($page-1)*$pagesize : 0;//數(shù)據(jù)獲取的起始位置。即limit條件的第一個(gè)參數(shù)。    $typesql = $typeid ? " WHERE typeid=$typeid" : '';//這個(gè)是用于首頁(yè)實(shí)現(xiàn)瀑布流加載,因?yàn)槭醉?yè)加載數(shù)據(jù)是無(wú)需分類(lèi)的,所以要加以判斷,如果無(wú)需    $total_sql = "SELECT COUNT(id) as num FROM `archives` $typesql ";    $temp = $dsql->GetOne($total_sql);    $total = 0;//數(shù)據(jù)總數(shù)    $load_num =0;    if(is_array($temp)){        $load_num= round(($temp['num']-15)/$pagesize);//要加載的次數(shù),因?yàn)槟J(rèn)已經(jīng)加載了        $total = $temp['num'];    }    $sql = "SELECT a.*,t.typedir,t.typename,t.isdefault,t.defaultname,t.namerule,    t.namerule2,t.ispart, t.moresite,t.siteurl,t.sitepath    FROM `archives` as a JOIN `arctype` AS t ON a.typeid=t.id $typesql ORDER BY id DESC LIMIT $start,$pagesize";    $dsql->SetQuery($sql);    $dsql->Execute('list');    $statu = 0;//是否有數(shù)據(jù),默認(rèn)沒(méi)有數(shù)據(jù)    $data = array();    $index = 0;    while($row = $dsql->GetArray("list")){        $row['info'] = $row['info'] = $row['infos'] = cn_substr($row['description'],160);        $row['id'] =  $row['id'];        $row['filename'] = $row['arcurl'] = GetFileUrl($row['id'],        $row['typeid'],$row['senddate'],$row['title'],$row['ismake'],        $row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],        $row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']);        $row['typeurl'] = GetTypeUrl($row['typeid'],$row['typedir'],        $row['isdefault'],$row['defaultname'],$row['ispart'],        $row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);        if($row['litpic'] == '-' || $row['litpic'] == ''){            $row['litpic'] = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';        }        if(!preg_match("#^http:////#i", $row['litpic']) &&$GLOBALS['cfg_multi_site'] == 'Y'){            $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];        }        $row['picname'] = $row['litpic'];//縮略圖        //$row['stime'] = GetDateMK($row['pubdate']);        $row['stime'] = date('Y-m-d H:i', $row['pubdate']);        $row['click'] = $row['click'];        $row['typelink'] = "".$row['typename']."";//分類(lèi)鏈        $row['fulltitle'] = $row['title'];//完整的標(biāo)題        $row['shorttitle'] = $row['shorttitle'];//副標(biāo)題        $row['title'] = cn_substr($row['title'], 80);//截取后的標(biāo)題        $data[$index] = $row;        $index++;    }    if(!empty($data)){        $statu = 1;//有數(shù)據(jù)    }    $result =array('statu'=>$statu,'list'=>$data,'total'=>$total,'load_num'=>$load_num);    echo json_encode($result);//返回?cái)?shù)據(jù)    exit();}
二、然后在需要使用瀑布流無(wú)線加載的織夢(mèng)dedecms模板里引用下面這個(gè)js代碼(這個(gè)js大家應(yīng)該不是很陌生,只要有用到JQ庫(kù)函數(shù)的話一定要引用這個(gè)js):

 

<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>

三、并在模板底部添加以下代碼:

<script type="text/javascript">var loadConfig = {                url_api:'/plus/list.php',                typeid:{dede:field name="typeid"/},                page:2,                pagesize:15,  //這個(gè)就是滑動(dòng)一次添加幾條信息的參數(shù)設(shè)置                loading : 0,                }function  loadMoreApply(){    if(loadConfig.loading == 0){         var typeid = loadConfig.typeid;         var page = loadConfig.page;         var pagesize = loadConfig.pagesize;         var url = loadConfig.url_api,data={ajax:'pullload',typeid:typeid,page:page,pagesize:pagesize};         var sTop = document.body.scrollTop || document.documentElement.scrollTop, dHeight = $(document).height(), cHeight = document.documentElement.clientHeight;         console.log(dHeight);                       if (sTop + cHeight >= dHeight - cHeight) {             loadConfig.loading = 1;            function ajax(url, data) {                                     $.ajax({url: url,data: data,async: false,type: 'GET',dataType: 'json',success: function(data) {                    addContent(data);                  }});            }            ajax(url,data);        }    }} function addContent (rs){    if(rs.statu== 1){        var data = rs.list;        var total = rs.total;        var arr=[];        var length = data.length;        for(var i=0;i<length;i++){            arr.push('<a href="'+data[i].arcurl+'" title="'+data[i].title+'">');            arr.push('<dl class="yz_card">');            arr.push('<dt class="yz_card_dt">');            arr.push('<img src="'+data[i].picname+'" alt="'+data[i].title+'">');            arr.push('</dt>');            arr.push('<dd class="yz_card_dd">');            arr.push('<p class="yz_card_p">'+data[i].title+'</p>');            arr.push('<div class="yz_card_icon">');            arr.push('<span class="yz_comment">');            arr.push(data[i].click);                                        arr.push('<em class="yz_icon_comment"><img src="/templets/default/images/pingluan.png" height="14"></em>');            arr.push('</span>');            arr.push('</div>');            arr.push('<div class="yz_datetime">'+data[i].stime+'</div>');            arr.push('</dd>');            arr.push('</dl>');            arr.push('</a>');        }        $('.arclist').append(arr.join(''));        loadConfig.load_num = rs.load_num;        if(total<loadConfig.page*loadConfig.pagesize || loadConfig.page > loadConfig.load_num){            window.removeEventListener('srcoll',loadMoreApply,false);        }        loadConfig.page++;        loadConfig.loading = 0;    }}function pullLoad(){    window.addEventListener('scroll', loadMoreApply, false);}pullLoad();</script>
上面的代碼中的$('.arclist').append(arr.join(''));里的arclist對(duì)應(yīng)模板內(nèi)列表的外框class屬性。

 

arr.push部分對(duì)應(yīng)的是列表中單篇文章的代碼。

到此織夢(mèng)dedecms瀑布流無(wú)限加載就實(shí)現(xiàn)了。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 沁水县| 临安市| 巩义市| 龙南县| 西吉县| 周宁县| 湘乡市| 舞钢市| 滕州市| 房山区| 拜泉县| 南靖县| 休宁县| 屏东县| 凤冈县| 茂名市| 扬中市| 东乌珠穆沁旗| 淳安县| 耿马| 柘城县| 山西省| 城步| 竹溪县| 贵南县| 兴化市| 临安市| 定州市| 正定县| 屯门区| 集安市| 淮南市| 乐平市| 昭苏县| 金川县| 安达市| 新宁县| 冷水江市| 星座| 霍城县| 沅江市|