zoukankan      html  css  js  c++  java
  • PHP+Ajax点击加载更多内容 -这个效果好,速度快,只能点击更多加载,不能滚动自动加载

    这个效果好,速度快,只能点击更多加载,不能滚动自动加载

    一、HTML部分

    <div id="more">  
         <div class="single_item">  
               <div class="element_head">  
                   <div class="date"></div>  
                   <div class="author"></div>  
                </div>  
                <div class="content"></div>  
         </div>  
         <a href="javascript:;" class="get_more">::点击加载更多内容::</a>  
    </div>

    引入jQuery插件和jquery.more.js加载更多插件

    <script type="text/javascript" src="jquery.js"></script>  
    <script type="text/javascript" src="jquery.more.js"></script>

    jQuery

    $(function(){  
        $('#more').more({'address': 'data.php'})  
    });

    data.php

    data.php接收前台页面提交过来的两个参数,$_POST['last']即开始记录数,$_POST['amount']即单次显示记录数,看SQL语句就明白,其实就是分页中用到的语句。

    require_once('connect.php'); 
     
    $last = $_POST['last']; 
    $amount = $_POST['amount']; 
     
    $query = mysql_query("select * from article order by id desc limit $last,$amount"); 
    while ($row = mysql_fetch_array($query)) { 
        $sayList[] = array( 
            'title' => "<a href='http://www.sucaihuo.com/js/".$row['id'].".html' target='_blank'>".$row['title']."</a>", 
            'author' => $row['id'], 
            'date' => date('m-d H:i', $row['addtime']) 
        ); 
    } 
    echo json_encode($sayList);

    jquery.more.js相关API

    参数 描述 默认值
    amount 每次显示记录数 10
    address 请求后台的地址 -
    format 数据传输格式 json
    template html记录DIV的class属性 .single_item -
    trigger 触发加载更多记录的class属性 .get_more -
    scroll 是否支持滚动触发加载 false
    offset 滚动触发加载时的偏移量 100

    七,源码下载

    链接: https://pan.baidu.com/s/1x5wRisLRxAIpuQUSkO0BOg 
    提取码: qya7
     
     
  • 相关阅读:
    MongoDB 2.4、备份
    MongoDB 2.3复制(副本集)
    MongoDB 2.2安全
    isMobile 一个简单的JS库,用来检测移动设备
    修改ECSHOP,支持图片云存储化(分离到专用图片服务器)
    压缩代码加速ecshop程序页面加载速度
    ecshop改造读写分离
    ecshop在nginx下实现负载均衡
    运用@media实现网页自适应中的几个关键分辨率
    在ECSHOP首页今日特价(促销商品)增加倒计时效果
  • 原文地址:https://www.cnblogs.com/lxwphp/p/9854467.html
Copyright © 2011-2022 走看看