本文实例为大家分享了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;/