iscroll動態(tài)加載數(shù)據(jù)完美解決方法
更新時間:2017年07月18日 09:15:16 作者:成大大
這篇文章主要為大家詳細介紹了iscroll動態(tài)加載數(shù)據(jù)的完美解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了iscroll動態(tài)加載數(shù)據(jù)的具體代碼,供大家參考,具體內(nèi)容如下
<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 = '數(shù)據(jù)更新時間:' + 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ù)更新時間:' + 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ù)更新時間:' + 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ù)更新時間:' + 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 */
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- 基于iScroll實現(xiàn)下拉刷新和上滑加載效果
- H5基于iScroll實現(xiàn)下拉刷新和上拉加載更多
- iscroll-probe實現(xiàn)下拉刷新和下拉加載效果
- 基于iscroll.js實現(xiàn)下拉刷新和上拉加載效果
- 基于HTML5上使用iScroll實現(xiàn)下拉刷新,上拉加載更多
- iOS開發(fā)中使用UIScrollView實現(xiàn)圖片輪播和點擊加載
- JQuery插件iScroll實現(xiàn)下拉刷新,滾動翻頁特效
- jQuery插件multiScroll實現(xiàn)全屏鼠標滾動切換頁面特效
- iOS應(yīng)用開發(fā)中UIScrollView滾動視圖的基本用法總結(jié)
- iscroll.js滾動加載實例詳解
相關(guān)文章
JavaScript本地存儲與會話存儲的實現(xiàn)介紹
本地存儲和會話存儲是比較常用的方法,你知道兩者的區(qū)別嗎,本文詳細的介紹了JavaScript中本地存儲(LocalStorage)和會話存儲(SessionStorage)的使用,具有一定的參考價值,感興趣的可以了解一下2022-08-08使用 JavaScript 進行函數(shù)式編程 (一) 翻譯
本文是函數(shù)式編程系列的第一篇文章。這里我會簡要介紹一下編程范式,然后會直接介紹使用 Javascript 進行函數(shù)式編程的概念,因為 JavsScript 是最被認可的函數(shù)式程序語言之一。我們鼓勵讀者通過參考資料部分進一步了解這一迷人的概念2015-10-10微信小程序在其他頁面監(jiān)聽globalData中值的變化
這篇文章主要給大家介紹了關(guān)于微信小程序如何在其他頁面監(jiān)聽globalData中值的變化的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學(xué)習(xí)或者使用微信小程序具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07