iscroll动态加载数据完美解决方法
作者:成大大 发布时间:2024-04-10 13:59:01
标签:iscroll,加载数据
本文实例为大家分享了iscroll动态加载数据的具体代码,供大家参考,具体内容如下
<div id="wrapper" class="margin-b90">
<div id="scroller">
<div id="pullDown">
<span class="pullDownLabel" style="text-align: center;">加载中...</span>
</div>
<div class="sps_itemBox ">
<div class="list_show">
<ul id="ulList"></ul>
</div>
</div>
<div id="pullUp">
<span class="pullUpLabel" style="text-align: center;">上拉加载...</span>
</div>
</div>
</div>
js.
// iScroll 滚动条/上拉刷新/下拉加载
var myScroll,
pullDownEl,
pullDownOffset,
pullUpEl,
pullUpOffset;
function loaded() {
pullDownEl = document.getElementById('pullDown');
pullDownOffset = pullDownEl.offsetHeight;
pullUpEl = document.getElementById('pullUp');
pullUpOffset = pullUpEl.offsetHeight;
myScroll = new iScroll('wrapper', {
useTransition: false,
topOffset: pullDownOffset,
btnOffset: pullUpOffset,
hideScrollbar: true,
fadeScrollbar: true,
onRefresh: function () {
if (pullDownEl.className.match('loading')) {
pullDownEl.className = '';
//pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';
pullDownEl.querySelector('.pullDownLabel').innerHTML = '数据更新时间:' + updateDatetime;
} else if (pullUpEl.className.match('loading')) {
pullUpEl.className = '';
pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载...';
}
},
onScrollMove: function () {
if (this.y > 5 && !pullDownEl.className.match('flip')) {
pullDownEl.className = 'flip';
//pullDownEl.querySelector('.pullDownLabel').innerHTML = '释放刷新...';
pullDownEl.querySelector('.pullDownLabel').innerHTML = '数据更新时间:' + updateDatetime;
this.minScrollY = 0;
} else if (this.y < 5 && pullDownEl.className.match('flip')) {
pullDownEl.className = '';
//pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';
pullDownEl.querySelector('.pullDownLabel').innerHTML = '数据更新时间:' + updateDatetime;
this.minScrollY = -pullDownOffset;
} else if (this.y < (this.maxScrollY - pullUpOffset - 40) && !pullUpEl.className.match('flip')) {
pullUpEl.className = 'flip';
pullUpEl.querySelector('.pullUpLabel').innerHTML = '释放加载...';
this.maxScrollY = this.maxScrollY - pullUpOffset;
}
//else if (this.y > (this.maxScrollY - pullUpOffset) && pullUpEl.className.match('flip')) {
// pullUpEl.className = '';
// pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载...';
// //this.maxScrollY = pullUpOffset;
//}
},
onScrollEnd: function () {
if (pullDownEl.className.match('flip')) {
pullDownEl.className = 'loading';
//pullDownEl.querySelector('.pullDownLabel').innerHTML = '数据刷新中...';
pullDownEl.querySelector('.pullDownLabel').innerHTML = '数据更新时间:' + updateDatetime;
myScroll.refresh();
} else if (pullUpEl.className.match('flip')) {
pullUpEl.className = 'loading';
pullUpEl.querySelector('.pullUpLabel').innerHTML = '数据加载中...';
setTimeout(function () { myScroll.refresh(); }, 3000);
}
}
});
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', function () { setTimeout(loaded, 200); }, false);
css
/* iScroll */
#wrapper{width:100%; position:absolute; top:0; bottom:0; z-index:1; overflow:hidden;}
#scroller{
width:100%; position:absolute; z-index:1;
-webkit-touch-callout:none; -webkit-tap-highlight-color:rgba(0,0,0,0);
}
#pullDown,
#pullUp{padding:15px 0 15px 60px; font-size:14px; line-height:27px; color:#303030;}
#pullDown{background:url(../images/loadBottom.png) no-repeat 30px center; background-size:27px 27px;}
#pullUp{background:url(../images/loadTop.png) no-repeat 30px center; background-size:27px 27px;}
#pullDown.flip{background:url(../images/loadTop.png) no-repeat 30px center; background-size:27px 27px;}
#pullUp.flip{background:url(../images/loadBottom.png) no-repeat 30px center; background-size:27px 27px;}
#pullDown.loading,
#pullUp.loading{background:url(../images/loading.gif) no-repeat 30px center; background-size:25px 27px;}
/* iScroll end */
0
投稿
猜你喜欢
- 本文使用css结合js技术给网页背景background 插入flash播放器播放音乐,想法很大胆,呵呵!刚刚乱试一翻搞出这个,有意思吗?请
- 最近在看python的算法书,之前在年前买的书,一直在工作间隙的时候,学习充电,终于看到这本书,但是确实又有点难,感觉作者写的代码太炫技 了
- 一直记不住在jupyter notebook配置多环境编译器技巧,今总结于此,也希望对其他小伙伴有所帮助,如果有用请点赞!1.对window
- class和id的命名,如果合理,可以使得文档具有清晰的结构我们现在解决办法就是使用现有的元素,通过给他们id或class而得到额外的信息。
- 1. 认识数据库1.1 数据库和数据结构的关系数据结构:是指相互之间存在一种或多种特定关系的数据元素的集合,是一个抽象的学科我们熟知的数据结
- ccs的优点:css相对xpath语法比xpath简洁,定位速度比xpath快css的缺点:css不支持用逻辑运算符来定位,而xpath支持
- 一、什么是NumPyNumpy--Numerical Python,是一个基于Python的可以存储和处理大型矩阵的库。几乎是Python
- 当我们在安装scrapy的过程中出现了Twisted错误,当我们有继续安装Twisted的时候,又继续报错,通过一系列的查询和了解,终于发现
- /* --注意:准备数据(可略过,非常耗时) CREATE TABLE CHECK1_T1 ( ID INT, C1 CHAR(8000)
- time模块中的三种时间表示方式:时间戳结构化时间对象格式化时间字符串1.时间戳时间戳1970.1.1到指定时间到间隔,单位是秒import
- 他们是如何不让我的Teleport和Webzip工作的?你也可以做得到哦: <%dim UserAgentUser
- 演示:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//
- 本文记录了NLTK 3.2.4 环境搭建的方法,供大家参考,具体内容如下系统环境:win7 32位python:2.7.13,后改为3.6.
- mysql主从搭建环境:ubuntu20.04.1,mysql:8.0.22。主:192.168.87.3备:192.168.87.6安装数
- 主要介绍常用的MySQL命令,包括连接数据库,修改密码,管理用户,操作数据库,操作数据表,数据库备份等,每个命令都配有实例说明,让大家更容易
- 就像HTML或者Python,Django模板语言同样提供代码注释。 注释使用 {# #} :{# This is a comment #}
- 使用如下命令为 ubuntu 系统安装 virtualenvsudo apt-get install python-virtualenv当我
- 算法简介鸡群算法,缩写为CSO(Chicken Swarm Optimization),尽管具备所谓仿生学的背景,但实质上是粒子群算法的一个
- image.jsp------------------------------生成随机验证码图片的Jsp页面 代码如下: <
- 本文实例讲述了Python使用ConfigParser模块操作配置文件的方法。分享给大家供大家参考,具体如下:一、简介用于生成和修改常见配置