iscroll動(dòng)態(tài)加載數(shù)據(jù)完美解決方法
本文實(shí)例為大家分享了iscroll動(dòng)態(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 滾動(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 */
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 基于iScroll實(shí)現(xiàn)下拉刷新和上滑加載效果
- H5基于iScroll實(shí)現(xiàn)下拉刷新和上拉加載更多
- iscroll-probe實(shí)現(xiàn)下拉刷新和下拉加載效果
- 基于iscroll.js實(shí)現(xiàn)下拉刷新和上拉加載效果
- 基于HTML5上使用iScroll實(shí)現(xiàn)下拉刷新,上拉加載更多
- iOS開發(fā)中使用UIScrollView實(shí)現(xiàn)圖片輪播和點(diǎn)擊加載
- JQuery插件iScroll實(shí)現(xiàn)下拉刷新,滾動(dòng)翻頁(yè)特效
- jQuery插件multiScroll實(shí)現(xiàn)全屏鼠標(biāo)滾動(dòng)切換頁(yè)面特效
- iOS應(yīng)用開發(fā)中UIScrollView滾動(dòng)視圖的基本用法總結(jié)
- iscroll.js滾動(dòng)加載實(shí)例詳解
相關(guān)文章
JavaScript本地存儲(chǔ)與會(huì)話存儲(chǔ)的實(shí)現(xiàn)介紹
本地存儲(chǔ)和會(huì)話存儲(chǔ)是比較常用的方法,你知道兩者的區(qū)別嗎,本文詳細(xì)的介紹了JavaScript中本地存儲(chǔ)(LocalStorage)和會(huì)話存儲(chǔ)(SessionStorage)的使用,具有一定的參考價(jià)值,感興趣的可以了解一下2022-08-08
使用 JavaScript 進(jìn)行函數(shù)式編程 (一) 翻譯
本文是函數(shù)式編程系列的第一篇文章。這里我會(huì)簡(jiǎn)要介紹一下編程范式,然后會(huì)直接介紹使用 Javascript 進(jìn)行函數(shù)式編程的概念,因?yàn)?JavsScript 是最被認(rèn)可的函數(shù)式程序語(yǔ)言之一。我們鼓勵(lì)讀者通過(guò)參考資料部分進(jìn)一步了解這一迷人的概念2015-10-10
JavaScript中實(shí)現(xiàn)塊作用域的方法
在Javascript中由于沒(méi)有作用域的概念,所以很容易發(fā)生標(biāo)識(shí)符名稱的沖突,尤其是在比較大的項(xiàng)目中,這類情況更容易發(fā)生2010-04-04
JavaScript中常見(jiàn)的事件用法小結(jié)
這篇文章主要介紹了JavaScript中常見(jiàn)的事件用法小結(jié),需要的朋友可以參考下2023-05-05
JavaScript實(shí)現(xiàn)瀑布流布局的3種方式
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)瀑布流布局的3種方式,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-12-12
10個(gè)功能強(qiáng)大的JavaScript動(dòng)畫庫(kù)分享
動(dòng)畫,從人群中脫穎而出、吸引訪客注意力的絕佳方式,本文將給大家分享10 個(gè)功能強(qiáng)大的 JavaScript 動(dòng)畫庫(kù),有了這 10 個(gè)功能強(qiáng)大的 JavaScript 庫(kù),創(chuàng)建動(dòng)畫再簡(jiǎn)單不過(guò)了,感興趣的同學(xué)可以參考閱讀2023-09-09
微信小程序在其他頁(yè)面監(jiān)聽globalData中值的變化
這篇文章主要給大家介紹了關(guān)于微信小程序如何在其他頁(yè)面監(jiān)聽globalData中值的變化的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用微信小程序具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07

