dedecms瀑布流ajax异步加载

   日期:2020-05-15     浏览:25    评论:0    
核心提示:dedecms瀑布流ajax异步加载话不多说,直接切入正题找到plus目录下的list.php在require_once(dirname(__FILE__).https://www.hanl
dedecms瀑布流ajax异步加载
话不多说,直接切入正题
 
找到plus目录下的list.php
 
 
require_once(dirname(__FILE__).https://www.hanlaba.com/skin/hanlaba/image/nopic.gif/../include/common.inc.phphttps://www.hanlaba.com/skin/hanlaba/image/nopic.gif);
 
 
下部增加
if(isset($_GET['ajax'])){
$typeid = isset($_GET['typeid']) ? intval($_GET['typeid']): 0;//传递过来的分类ID
  $page = isset($_GET['page']) ? intval($_GET['page']): 0;//页码
  $pagesize = isset($_GET['pagesize']) ? intval($_GET['pagesize']): 15;//每页多少条,也就是一次加载多少条数据
  $start = $page>0 ? ($page-1)*$pagesize : 0;//数据获取的起始位置。即limit条件的第一个参数。
  $typesql = $typeid ? https://www.hanlaba.com/skin/hanlaba/image/nopic.gif WHERe typeid=$typeidhttps://www.hanlaba.com/skin/hanlaba/image/nopic.gif : '';//这个是用于首页实现瀑布流加载,因为首页加载数据是无需分类的,所以要加以判断,如果无需
   $total_sql = https://www.hanlaba.com/skin/hanlaba/image/nopic.gifSELECt COUNT(id) as num FROM `#@__archives`  $typesql https://www.hanlaba.com/skin/hanlaba/image/nopic.gif;
  $temp = $dsql->GetOne($total_sql);
  $total = 0;//数据总数
  $load_num =0;
  if(is_array($temp)){
    $load_num= round(($temp['num']-15)/$pagesize);//要加载的次数,因为默认已经加载了
    $total = $temp['num'];
  }
  $sql = https://www.hanlaba.com/skin/hanlaba/image/nopic.gifSELECt 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,$pagesizehttps://www.hanlaba.com/skin/hanlaba/image/nopic.gif;
//echo https://www.hanlaba.com/skin/hanlaba/image/nopic.gif$sqlhttps://www.hanlaba.com/skin/hanlaba/image/nopic.gif;
   $dsql->SetQuery($sql);
    $dsql->Execute('list');
   $statu = 0;//是否有数据,默认没有数据
   $data = array();
     $index = 0;
while($row = $dsql->GetArray(https://www.hanlaba.com/skin/hanlaba/image/nopic.giflisthttps://www.hanlaba.com/skin/hanlaba/image/nopic.gif)){
    $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(https://www.hanlaba.com/skin/hanlaba/image/nopic.gif#^http:\/\/#ihttps://www.hanlaba.com/skin/hanlaba/image/nopic.gif, $row['litpic']) &&$GLOBALS['cfg_multi_site'] == 'Y'){
    $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
   }
  $row['picname'] = $row['litpic'];//缩略图
   $row['stime'] = GetDateMK($row['pubdate']);
  $row['typelink'] = https://www.hanlaba.com/skin/hanlaba/image/nopic.gif<a href='https://www.hanlaba.com/skin/hanlaba/image/nopic.gif.$row['typeurl'].https://www.hanlaba.com/skin/hanlaba/image/nopic.gif'>https://www.hanlaba.com/skin/hanlaba/image/nopic.gif.$row['typename'].https://www.hanlaba.com/skin/hanlaba/image/nopic.gif</a>https://www.hanlaba.com/skin/hanlaba/image/nopic.gif;//分类链
  $row['fulltitle'] = $row['title'];//完整的标题
  $row['shorttitle'] = $row['shorttitle'];//副标题
  $row['title'] = cn_substr($row['title'], 60);//截取后的标题
   $data[$index] = $row;
   $index++;
}
if(!empty($data)){
$statu = 1;//有数据
}
$result =array('statu'=>$statu,'list'=>$data,'total'=>$total,'load_num'=>$load_num);
echo json_encode($result);//返回数据
exit();
}
调用数据库增加后
 
在模板页面调用增加JQ库
 
<script src="https://www.hanlaba.com/skin/hanlaba/image/nopic.gifhttp://libs.baidu.com/jquery/1.9.0/jquery.jshttps://www.hanlaba.com/skin/hanlaba/image/nopic.gif"></script>
底部增加调用JS
<script type=https://www.hanlaba.com/skin/hanlaba/image/nopic.giftext/javascripthttps://www.hanlaba.com/skin/hanlaba/image/nopic.gif>
var loadConfig = {
url_api:'/plus/list.php',
typeid:0,
page:2,
pagesize:3,
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=https://www.hanlaba.com/skin/hanlaba/image/nopic.gif'+data[i].arcurl+'https://www.hanlaba.com/skin/hanlaba/image/nopic.gif>');
arr.push('<div class=https://www.hanlaba.com/skin/hanlaba/image/nopic.gifitemhttps://www.hanlaba.com/skin/hanlaba/image/nopic.gif>');
arr.push('<div class=https://www.hanlaba.com/skin/hanlaba/image/nopic.gifthumbnailhttps://www.hanlaba.com/skin/hanlaba/image/nopic.gif>');
arr.push('<img class=https://www.hanlaba.com/skin/hanlaba/image/nopic.gifimg-responsivehttps://www.hanlaba.com/skin/hanlaba/image/nopic.gif src="https://www.hanlaba.com/skin/hanlaba/image/nopic.gif"'+data[i].picname+'https://www.hanlaba.com/skin/hanlaba/image/nopic.gif width=460 height=255 />');
arr.push('</div>');
arr.push('<div class=https://www.hanlaba.com/skin/hanlaba/image/nopic.gifcaptionhttps://www.hanlaba.com/skin/hanlaba/image/nopic.gif>');
arr.push('<h3>'+data[i].title+'</h3>');
arr.push('<div class=https://www.hanlaba.com/skin/hanlaba/image/nopic.gifplacehttps://www.hanlaba.com/skin/hanlaba/image/nopic.gif>'+data[i].shorttitle+'</div>');
arr.push('</div>');
arr.push('</div>');
arr.push('</a>');
}
$('.data-list').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()
checkMobile();
 
</script>
$('.data-list').append(arr.join('')); 里的 data-list 对应模板内列表的外框
 
arr.push部分对应的是列表代码,
 
 
 
这样首页即可使用了。
 
列表页只需把typeid:0, 修改为typeid:{dede:field name=https://www.hanlaba.com/skin/hanlaba/image/nopic.giftypeidhttps://www.hanlaba.com/skin/hanlaba/image/nopic.gif/},即可
 
简单通俗易懂
离石区网站建设 郑州展柜制作 开县化妆品展柜 郑州展柜厂 山南地区化妆品展柜 郑州展柜 宿州化妆品展柜 信阳铁木结合柜  红桥区化妆品展柜 龙泉驿网站建设 北川县网站建设 船山网站建设 于都县网站建设 江城网站建设 扬州网站建设 郑州格力空调售后电话 郑州格力空调售后服务电话

(本文内容可能来源于网络,也可能由用户自行原创,如有侵权请联系删除)
 
打赏
 
更多>同类资讯
更多>您可能感兴趣的内容
0相关评论

电商热门产品排行榜(20200523更新)
推荐图文
推荐资讯
点击排行