您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)iscroll如何動(dòng)態(tài)加載數(shù)據(jù),小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
具體內(nèi)容如下
<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 滾動(dòng)條/上拉刷新/下拉加載 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 = '數(shù)據(jù)更新時(shí)間:' + 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 = '數(shù)據(jù)更新時(shí)間:' + updateDatetime; this.minScrollY = 0; } else if (this.y < 5 && pullDownEl.className.match('flip')) { pullDownEl.className = ''; //pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...'; pullDownEl.querySelector('.pullDownLabel').innerHTML = '數(shù)據(jù)更新時(shí)間:' + 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 = '數(shù)據(jù)刷新中...'; pullDownEl.querySelector('.pullDownLabel').innerHTML = '數(shù)據(jù)更新時(shí)間:' + updateDatetime; myScroll.refresh(); } else if (pullUpEl.className.match('flip')) { pullUpEl.className = 'loading'; pullUpEl.querySelector('.pullUpLabel').innerHTML = '數(shù)據(jù)加載中...'; 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 */
關(guān)于“iscroll如何動(dòng)態(tài)加載數(shù)據(jù)”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。