本文实例为大家分享了iscroll动态加载数据的具体代码,供大家参考,具体内容如下
<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 = '数据更新时间:' + 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 */
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年11月18日
2024年11月18日
- 【雨果唱片】中国管弦乐《鹿回头》WAV
- APM亚流新世代《一起冒险》[FLAC/分轨][106.77MB]
- 崔健《飞狗》律冻文化[WAV+CUE][1.1G]
- 罗志祥《舞状元 (Explicit)》[320K/MP3][66.77MB]
- 尤雅.1997-幽雅精粹2CD【南方】【WAV+CUE】
- 张惠妹.2007-STAR(引进版)【EMI百代】【WAV+CUE】
- 群星.2008-LOVE情歌集VOL.8【正东】【WAV+CUE】
- 罗志祥《舞状元 (Explicit)》[FLAC/分轨][360.76MB]
- Tank《我不伟大,至少我能改变我。》[320K/MP3][160.41MB]
- Tank《我不伟大,至少我能改变我。》[FLAC/分轨][236.89MB]
- CD圣经推荐-夏韶声《谙2》SACD-ISO
- 钟镇涛-《百分百钟镇涛》首批限量版SACD-ISO
- 群星《继续微笑致敬许冠杰》[低速原抓WAV+CUE]
- 潘秀琼.2003-国语难忘金曲珍藏集【皇星全音】【WAV+CUE】
- 林东松.1997-2039玫瑰事件【宝丽金】【WAV+CUE】