iscroll动态加载数据完美解决方法

作者:成大大 时间:2024-04-10 13:59:01 

本文实例为大家分享了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 */
标签:iscroll,加载数据
0
投稿

猜你喜欢

  • Python全栈之进程和守护进程

    2021-11-25 18:05:44
  • Python实现点阵字体读取与转换的方法

    2022-11-08 08:33:27
  • PHPStudy hosts文件可能不存在或被阻止打开及同步hosts失败问题

    2023-06-08 10:29:10
  • php.ini修改php上传文件大小限制的方法详解

    2023-09-11 04:03:12
  • 讲解SQL Server数据库的触发器安全隐患

    2009-01-13 14:01:00
  • pandas计算最大连续间隔的方法

    2022-05-23 12:05:21
  • WEB前端开发经验总结 Ⅰ

    2008-06-12 12:23:00
  • python 用matplotlib绘制折线图详情

    2022-03-23 16:38:19
  • Go+Kafka实现延迟消息的实现示例

    2024-05-22 10:14:29
  • python如何读取.mtx文件

    2023-11-17 21:26:55
  • Go语言HttpRouter路由使用方法详解

    2024-05-09 14:56:31
  • jszip插件实现图片打包下载的方法分析 <font color=red>原创</font>

    2024-05-09 10:34:34
  • Vscode常用快捷键列表、插件安装、console.log详解

    2023-02-11 01:29:04
  • asp函数遍历文件夹代码

    2010-06-21 10:38:00
  • 使用client-go工具调用kubernetes API接口的教程详解(v1.17版本)

    2024-05-08 10:52:08
  • 分面搜索(Faceted Search)

    2009-07-31 12:44:00
  • pandas || df.dropna() 缺失值删除操作

    2023-07-10 06:51:06
  • 使用PHP获取当前url路径的函数以及服务器变量

    2023-10-31 02:31:34
  • Sublime Text4 配置 Python3 环境、代码提示、编译报错的解决方案

    2021-09-24 12:00:03
  • Mysql数据库之索引优化

    2024-01-23 19:27:40
  • asp之家 网络编程 m.aspxhome.com