这篇文章将为大家详细讲解有关iscroll如何动态加载数据,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
具体内容如下
<div id="wrapper" class="margin-b90"> <div id="scroller"> <div id="pullDown"> <span class="pullDownLabel" >加载中...</span> </div> <div class="sps_itemBox "> <div class="list_show"> <ul id="ulList"></ul> </div> </div> <div id="pullUp"> <span class="pullUpLabel" >上拉加载...</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如何动态加载数据”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。