无限滚动 无法实现问题
将SUI的无限滚动 js 源码复制到项目中,并没有实现无限滚,控制台并没有出现异常信息,经多次测试发现,每次执行到
$(document).on('infinite','.infinite-scroll-bottom',null,function() {}函数时就进入了zepto.min.js,
$(document).on('infinite','.infinite-scroll-bottom',null,function() {}函数内的所有方法都无法执行。很苦恼。。。
以下是源码:
// 加载flag
var loading = false;
// 最多可加载的条目
var maxItems = 10;
// 每次加载添加多少条目
var itemsPerLoad = 5;
function addItems(number, lastIndex) {
// 生成新条目的HTML
var html = '';
for (var i = lastIndex + 1; i <= lastIndex + number; i++) {
html +='<div class="card">\n' +
' <div class="card-header">新的公布:</div>\n' +
' <div class="card-content">\n' +
' <div class="list-block media-list">\n' +
' <ul class="list-blocker">\n' +
' <li class="item-content">\n' +
' <div class="item-media">\n' +
' <img src="http://gqianniu.alicdn.com/bao/uploaded/i4//tfscom/i3/TB10LfcHFXXXXXKXpXXXXXXXXXX_!!0-item_pic.jpg_250x250q60.jpg" width="44">\n' +
' </div>\n' +
' <div class="item-inner">\n' +
' <div class="item-title-row">\n' +
' <div class="item-title">标题</div>\n' +
' </div>\n' +
' <div class="item-subtitle">子标题</div>\n' +
' </div>\n' +
' </li>\n' +
' </ul>\n' +
' </div>\n' +
' </div>\n' +
' <div class="card-footer">\n' +
' <span>2015/01/15</span>\n' +
' <span>5 评论</span>\n' +
' </div>\n' +
' </div> \n' +
'</div>';
}
// 添加新条目
$('.infinite-scroll-bottom .list-container').append(html);
}
//预先加载5条
addItems(itemsPerLoad, 0);
// 上次加载的序号
var lastIndex = 5;
console.log("infinite运行前:");
// 注册'infinite'事件处理函数
$(document).on('infinite','.infinite-scroll-bottom',null,function() {
console.log("infinite正在运行:")
// 如果正在加载,则退出
if (loading) return;
// 设置flag
loading = true;
// 模拟1s的加载过程
setTimeout(function() {
// 重置加载flag
loading = false;
if (lastIndex >= maxItems) {
// 加载完毕,则注销无限加载事件,以防不必要的加载
$.detachInfiniteScroll($('.infinite-scroll'));
// 删除加载提示符
$('.infinite-scroll-preloader').remove();
return;
}
// 添加新条目
addItems(itemsPerLoad, lastIndex);
// 更新最后加载的序号
lastIndex = $('.list-container li').length;
//容器发生改变,如果是js滚动,需要刷新滚动
$.refreshScroller();
}, 1000);
});
console.log("infinite运行后:")
正在回答 回答被采纳积分+1
老师您好,控制台没有任何提示,但下拉到第20条item时,就只有那个加载提示,并不会出现新的item。
下面是html源码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>商家列表</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<link rel="shortcut icon" href="/favicon.ico">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="stylesheet"
href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
<link rel="stylesheet"
href="//g.alicdn.com/msui/sm/0.6.2/css/sm-extend.min.css">
<link rel="stylesheet"
href="/resources/css/shopList.css">
</head>
<body>
<div class="page-group infinite-scroll infinite-scroll-bottom" data-distance="100">
<div class="page page-current">
<header class="bar bar-nav" style="padding-top: 8px;">
<!--<h1 class='title'>商铺列表</h1>-->
<div class="row">
<div class="col-33" style="padding-top: 5px;">
<a class="black" style="color: grey;" href="#">返回</a>
</div>
<div class="col-33" style="text-align: center;font-size: 1rem">商家列表</div>
<div class="col-33" style="color: grey;"></div>
</div>
</header>
<div class="bar bar-header-secondary">
<div class="searchbar">
<a href="#" class="searchbar-cancel">搜索</a>
<div class="search-input">
<label class="icon icon-search" for="search"></label>
<input type="search" id='search' placeholder='输入关键字...'/>
</div>
</div>
</div>
<!-- 工具栏 -->
<nav class="bar bar-tab">
<a class="tab-item external active" href="#">
<span class="icon icon-home"></span>
<span class="tab-label">首页</span>
</a>
<a class="tab-item external" href="#">
<span class="icon icon-me"></span>
<span class="tab-label">文案</span>
<span class="badge">2</span>
</a>
<a class="tab-item external" href="#">
<span class="icon icon-star"></span>
<span class="tab-label">收藏</span>
</a>
<a class="tab-item external" href="#">
<span class="icon icon-cart"></span>
<span class="tab-label">文案</span>
</a>
<a class="tab-item external" href="#">
<span class="icon icon-settings"></span>
<span class="tab-label">设置</span>
</a>
</nav>
<div class="content">
<div class="content-padded">
<div class="row shopCategoryList">
<p class="col-33"><a href="#" class="button shopCategory">全部类别</a></p>
</div>
<div class="item-input">
<input type="hidden" id="area_picker_value" value=""/>
<input type="text" value="所有街道" id='area_picker' placeholder="所有街道"/>
</div>
<!-- 添加 class infinite-scroll 和 data-distance 向下无限滚动可不加infinite-scroll-bottom类,这里加上是为了和下面的向上无限滚动区分-->
<div class="infinite-scroll infinite-scroll-bottom" data-distance="100">
<div class="list-block">
<ul class="list-container">
</ul>
</div>
<!-- 加载提示符 -->
<div class="infinite-scroll-preloader">
<div class="preloader"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type='text/javascript'
src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript'
src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript'
src='//g.alicdn.com/msui/sm/0.6.2/js/sm-extend.min.js' charset='utf-8'></script>
<!--自己配置的js文件-->
<script type='text/javascript'
src='../resources/js/shopList.js' charset='utf-8'></script>
<script type='text/javascript'
src='../resources/js/infinite-scroll.js' charset='utf-8'></script>
<script type='text/javascript'
src='../resources/js/common/common.js' charset='utf-8'></script>
</body>
</html>
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星