迅睿CMS模板实现AJAX瀑布流滚动加载/点击加载更多
迅睿函数大全迅睿基础设置迅睿二次开发迅睿模版制作迅睿缓存在线生成迅睿CMS标签大全
注意:如果开启了开发者模式,则加载完后无法显示“已经显示完了”,点击加载更多按钮也无效,关闭开发者模式即可。
滚动加载原理是当页面向下滚动时自动加载下一页数据并填充到当前页面,实现无刷新加载。
一、用于栏目列表
1、创建目标list_data.html专门用来写栏目分页循环标签的目标文件
{module catid=$catid order=updatetime page=1}
<div class="article-list>
<a href="{$t.url}">
{$t.title}
</a>
</div>
{/module}2、在list.html中标记显示容器div
<div class="article_info" id="content_list">
{template "list_data.html"}
</div>默认加载了第一页数据
3、在页面底部写加载的js
var Mpage=1;
//滚动显示更多
var scroll_get = true; //做个标志,不要反反复复的加载
$(document).ready(function () {
$(window).scroll(function () {
if (scroll_get==true && (400 + $(window).scrollTop())>($(document).height() - $(window).height())) {
scroll_get = false;
layer.msg('内容加截中,请稍候',{time:1000});
dr_ajax_load_more();
}
});
});
function dr_ajax_load_more(){
Mpage++;
$.get('/index.php?s=api&c=api&m=template&name=list_data.html&module={MOD_DIR}&catid={$catid}&format=json&page='+Mpage+'&'+Math.random(),function(res){
$('.footer-cont').hide();
if(res.code==1){
if(res.msg==''){
//这里的判断条件需要结合list_data.html模板来写,否则会出现无限的加载了
layer.msg("已经显示完了",{time:500});
}else{
$('#content_list').append(res.msg);
scroll_get = true;
}
}else{
layer.msg(res.msg,{time:2500});
}
}, 'json');
}#content_list就是(2)中的容器ID
二、用于搜索页面
1、创建目标search_data.html专门用来写搜索分页循环标签的目标文件
{search module=MOD_DIR id=$searchid total=$sototal order=$params.order catid=$catid page=1 pagesize=10 urlrule=$urlrule}
<div class="article-list>
<a href="{$t.url}">
{$t.title}
</a>
</div>
{/search}2、在search.html中标记显示容器div
<div class="article_info" id="content_list">
{template "search_data.html"}
</div>默认加载了第一页数据
加载按钮
<div class="ajax_btn margin-top-20" id="is_ajax_btn"> <a href="javascript:dr_ajax_load_more();" class="btn default btn-block"> 加载更多 </a> </div>
3、在页面底部写加载的js
var Mpage=1;
//滚动显示更多
var scroll_get = true; //做个标志,不要反反复复的加载
$(document).ready(function () {
$(window).scroll(function () {
if (scroll_get==true && (400 + $(window).scrollTop())>($(document).height() - $(window).height())) {
scroll_get = false;
layer.msg('内容加截中,请稍候',{time:1000});
dr_ajax_load_more();
}
});
});
function dr_ajax_load_more(){
Mpage++;
$.get('/index.php?s=api&c=api&m=template&name=search_data.html&module={MOD_DIR}&catid={$catid}&searchid={$searchid}&sototal={$sototal}&order={$params.order}&format=json&page='+Mpage+'&'+Math.random(),function(res){
$('.footer-cont').hide();
if(res.code==1){
if(res.msg==''){
//这里的判断条件需要结合list_data.html模板来写,否则会出现无限的加载了
$('#is_ajax_btn').hide();
layer.msg("已经显示完了",{time:500});
}else{
$('#content_list').append(res.msg);
scroll_get = true;
}
}else{
layer.msg(res.msg,{time:2500});
}
}, 'json');
}#content_list就是(2)中的容器ID
三、用于主站首页
1、创建目标index_data.html专门用来写搜索分页循环标签的目标文件
{module module=news page=1 pagesize=10 urlrule=index.php}
<div class="article-list>
<a href="{$t.url}">
{$t.title}
</a>
</div>
{/module}主站时需要指定module=具体模块目录
2、在index.html中标记显示容器div
<div class="article_info" id="content_list">
{template "index_data.html"}
</div>默认加载了第一页数据
3、在页面底部写加载的js
var Mpage=1;
//滚动显示更多
var scroll_get = true; //做个标志,不要反反复复的加载
$(document).ready(function () {
$(window).scroll(function () {
if (scroll_get==true && (400 + $(window).scrollTop())>($(document).height() - $(window).height())) {
scroll_get = false;
layer.msg('内容加截中,请稍候',{time:1000});
dr_ajax_load_more();
}
});
});
function dr_ajax_load_more(){
Mpage++;
$.get('/index.php?s=api&c=api&m=template&name=index_data.html&format=json&page='+Mpage+'&'+Math.random(),function(res){
$('.footer-cont').hide();
if(res.code==1){
if(res.msg==''){
//这里的判断条件需要结合list_data.html模板来写,否则会出现无限的加载了
layer.msg("已经显示完了",{time:500});
}else{
$('#content_list').append(res.msg);
scroll_get = true;
}
}else{
layer.msg(res.msg,{time:2500});
}
}, 'json');
}#content_list就是(2)中的容器ID
四、用于模块首页
1、创建目标news/module_data.html专门用来写搜索分页循环标签的目标文件
{module module=MOD_DIR page=1 pagesize=10 urlrule=index.php}
<div class="article-list>
<a href="{$t.url}">
{$t.title}
</a>
</div>
{/module}2、在news/index.html中标记显示容器div
<div class="article_info" id="content_list">
{template "module_data.html"}
</div>默认加载了第一页数据
3、在页面底部写加载的js
var Mpage=1;
//滚动显示更多
var scroll_get = true; //做个标志,不要反反复复的加载
$(document).ready(function () {
$(window).scroll(function () {
if (scroll_get==true && (400 + $(window).scrollTop())>($(document).height() - $(window).height())) {
scroll_get = false;
layer.msg('内容加截中,请稍候',{time:1000});
dr_ajax_load_more();
}
});
});
function dr_ajax_load_more(){
Mpage++;
$.get('/index.php?s=api&c=api&m=template&name=module_data.html&module={MOD_DIR}&format=json&page='+Mpage+'&'+Math.random(),function(res){
$('.footer-cont').hide();
if(res.code==1){
if(res.msg==''){
//这里的判断条件需要结合list_data.html模板来写,否则会出现无限的加载了
layer.msg("已经显示完了",{time:500});
}else{
$('#content_list').append(res.msg);
scroll_get = true;
}
}else{
layer.msg(res.msg,{time:2500});
}
}, 'json');
}#content_list就是(2)中的容器ID
------------
题外判断,判断某个div是否滚到底部
本文属原创,转载请注明原文:https://www.zhimatong.com/jiaocheng/1008.html
为保证教程的实用性及扩大知识面覆盖,如果您有相似问题而未解决,可联系在线客服免费技术支持。
热门主题
相关阅读
- Bootstrap的datetimepicker插件用法总结(基于迅睿CMS)
- 迅睿CMS搜索页等调用指定栏目数据dr_cat_value/dr_share_cat_value的用法
- 迅睿开发者模式如何用,迅睿CMS如何去掉页面右下角的火的标志
- 迅睿XunRuiCMS手机站点3种设置模式详解
- XunRuiCMS网站seo标题,关键词,描述等设置说明
- 迅睿CMS会员登录/注册后跳转到指定链接的方法
- 迅睿CMS联系方式等信息的修改方法
- 迅睿CMS模板制作:模块内容列表循环module标签的用法详解
- 迅睿CMS整合layui+ajax实现联动菜单多条件搜索的方法
- 详解迅睿模版安装调试及注意事项
- 迅睿CMS生成静态HTML,提示模版文件不存在的解决方法
- 迅睿CMS通过URL找到路由控制器的方法



交流群
购物车