帝国CMS二次开发ajax点击加载更多内容
作者:
美文苑 发表于:
浏览:
47次 字数:
3720 原创
级别:
站长2021-06-12 01:06:541018540
总稿:
69
篇,
月稿:
0
篇
ajax点击加载更多内容
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <link rel="stylesheet" href="[!--news.url--]skin/listnews/css/listnews.css">
- </head>
- <body>
- <div class="main-list">
- <ul id="list">
- </ul>
-
- <div class="load-more">
- <div class="add-more" style="display: flex">
- <i></i>
- <span>加载更多</span>
- </div>
- <div class="add-ing" style="display: none">
- <i></i>
- <span>加载中...</span>
- </div>
- </div>
- </div>
-
-
- <script src="[!--news.url--]skin/listnews/js/jquery.min.js"></script>
- <script>
- (function (win, $) {
- $.listnews = {
- pageNum: 0,
- initLoadMore() {
- let _self = this;
- $(".load-more").on('click', '.add-more', function () {
- $(this).css({ display: 'none' }).siblings('.add-ing').css({ display: 'flex' });
- _self.pageNum++;
- _self.initGetData(_self.pageNum);
- setTimeout(() => {
- $(this).css({ display: 'flex' }).siblings('.add-ing').css({ display: 'none' });
- }, 1000)
- })
- },
-
- initGetData(index) {
- let _this = this;
- $.ajax({
- url: '[!--news.url--]e/extend/listnews/?page=' + index + '&pageNum=5&classid=13',
-
-
-
-
-
-
- type: 'get',
- dataType: 'json',
- success: function (jsonData) {
- var html = '';
- if (jsonData.info) {
- jsonData.info.forEach(function (val) {
- html += `<li class="item">
- <a href="${val.titleurl}"><p>${val.title}</p><span class="date">${val.newstime}</span></a>
- </li>`;
- })
- $('#list').append(html);
- }
- }
- })
- },
-
- init() {
- this.initGetData(this.pageNum);
- this.initLoadMore();
- }
- }
- $.listnews.init();
- })(window, jQuery)
- </script>
- </body>
- </html>
2,css代码
- @charset "utf-8";
-
- .main-list{ clear:both;}
- .main-list ul li{ clear:both; list-style:none;}
- .main-list ul li p{ float:left;}
- .main-list ul li span{ float:right;}
- .load-more {clear:both;width: 100%;margin: 20px 0;border: 1px solid #e5e5e5;border-radius: 3px;text-align: center;cursor: pointer;position: relative;font: normal 20px/30px "Microsoft Yahei";color: #404040;height: 60px;}
- .load-more:hover {color: #0b6695;border-color: #0b6695;}
- .load-more .add-more, .load-more .add-ing {width: 100%;height: 100%;display: flex;justify-content: center;align-items: center;}
- .load-more .add-more i {display: block;width: 20px;height: 20px;overflow: hidden;margin: 5px 10px;background: url("../images/add_more.png") no-repeat 0 0;font-size: 40px;font-style: normal;-webkit-transition: transform .3s;-o-transition: transform .3s;transition: transform .3s;}
- .load-more .add-more:hover i {background-position: 0 -50px;-webkit-transform: rotate(90deg);-ms-transform: rotate(90deg);-o-transform: rotate(90deg);transform: rotate(90deg);}
- .load-more .add-ing {color: #f04343;}
- .load-more .add-ing i {display: block;width: 24px;height: 24px;overflow: hidden;margin: 5px 12px;background: url("../images/add_more.png") no-repeat 0 -100px;font-size: 40px;-webkit-transform-origin: center;-moz-transform-origin: center;-ms-transform-origin: center;-o-transform-origin: center;transform-origin: center;-webkit-animation: rotateIn .8s linear infinite;-moz-animation: rotateIn .8s linear infinite;-ms-animation: rotateIn .8s linear infinite;-o-animation: rotateIn .8s linear infinite;animation: rotateIn .8s linear infinite;}
3,index.php
- <?php
- require('../../class/connect.php');
- require('../../class/db_sql.php');
- require('../../data/dbcache/class.php');
- $link=db_connect();
- $empire=new mysqlquery();
- $editor=1;
-
-
- $page=intval($_GET[page]);
- $pageNum=intval($_GET[pageNum]);
- $classid=intval($_GET[classid]);
- $tool=$page*$pageNum;
-
- $mysql=$empire->query("select * from {$dbtbpre}ecms_news where classid=$classid order by newstime desc limit $tool,$pageNum");
- while($r=$empire->fetch($mysql))
- {
- $json_arr[] = array(
- "title"=>$r['title'],
- "id"=>$r['id'],
- "classid"=>$r['classid'],
- "newstime"=>date("Y-m-d H:i:s",$r['newstime']),
- "titleurl"=>$r['titleurl']
- );
- }
-
- $result=array('info'=>$json_arr,'pageNum'=>$tool);
- $json=json_encode($result);
- echo $json;
-
- db_close();
- $empire=null;
- ?>
【审核人:站长】
-
-
技术文摘
-
查看更多技术文摘