您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。