iscroll.js滾動(dòng)加載實(shí)例詳解
滾動(dòng)加載是個(gè)好東西,可以解決一次加載過(guò)多的尷尬,其實(shí)就是變相的分頁(yè),總結(jié)下這個(gè)輪子的用法,挺簡(jiǎn)單的。
首先是html結(jié)構(gòu):
<div class=" saleRecord panelList clear" style="position:relative;height:400px;"> <div id="wrapper"> <div id="scroller"> <ul id="thelist"> @foreach (var item in ViewBag.***) { if (item.IsPay == true) { <li> <div class="panelListItemForALL"> <table class="allRecordTable"> <tbody> <tr> <td>***</td> <td>@item.***</td> </tr> <tr> <td>***</td> <td>@item.***</td> </tr> <tr> <td>***</td> <td>@item.***</td> </tr> </tbody> </table> </div> </li> } } </ul> <div id="more">加載更多</div> </div> </div>
然后是css樣式:
#wrapper { position: absolute; z-index: 1; top: 0; bottom: 0; left: 0; width: 100%; overflow: hidden; } #scroller { position: absolute; z-index: 1; -webkit-tap-highlight-color: rgba(0,0,0,0); width: 100%; -webkit-transform: translateZ(0); -moz-transform: translateZ(0); -ms-transform: translateZ(0); -o-transform: translateZ(0); transform: translateZ(0); -webkit-touch-callout: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; -webkit-text-size-adjust: none; -moz-text-size-adjust: none; -ms-text-size-adjust: none; -o-text-size-adjust: none; text-size-adjust: none; } #more { text-align:center; }
需要的話,給父元素套上position:relative屬性
最后是腳本中的初始化和獲取數(shù)據(jù):
var pagenum = 1, update = true, id=ID; var myScroll; setTimeout(function(){ myScroll = new IScroll('#wrapper', { mouseWheel: true, click: true }); myScroll.on('scrollEnd', function () { //console.log(this.y +"|||"+this.maxScrollY); //如果滑動(dòng)到底部,則加載更多數(shù)據(jù)(距離最底部10px高度) if ((this.y - this.maxScrollY) == 0) { getMore(); } }); },100 ); function getMore() { var that = document.getElementById("more"); pagenum++; $.ajax({ url: '/***/getPage', data: {'currentPage':pagenum,'id':id}, type: 'POST', datatype: "json", success: function (data) { //alert(data); var list = data.List; if (list.length < 1) { pagenum--; that.innerHTML = "已經(jīng)沒(méi)有更多了..."; return; } var ul = document.getElementById("thelist"); for (var i = 0; i < list.length; i++) { var str = "<li>"; str += "<div class=\"panelListItemForALL\"><table class=\"allRecordTable\"><tbody><tr><td>***</td><td>"+list[i].OrderCode+"</td>"; str += "</tr><tr><td>***</td><td>"+list[i].GoodsName+"</td></tr>"; str += "<tr><td>***</td><td>"+ data.DatatimeArray[i] +"</td>"; str += "</tr></tbody></table></div>"; str += "</li>"; ul.innerHTML += str; myScroll.refresh(); } } }); }
把相應(yīng)的數(shù)據(jù)填充進(jìn)去就好,當(dāng)然控制器里要寫一個(gè)分頁(yè)獲取數(shù)據(jù)的方法,通過(guò)這里的ajax獲取。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
微信小程序?qū)崙?zhàn)篇之購(gòu)物車的實(shí)現(xiàn)代碼示例
本篇文章主要介紹了微信小程序?qū)崙?zhàn)篇之購(gòu)物車的實(shí)現(xiàn)代碼示例,詳細(xì)的介紹了購(gòu)物車的功能實(shí)現(xiàn),具有一定的參考價(jià)值,有興趣的可以了解一下2017-11-11echarts實(shí)現(xiàn)詞云自定義形狀的示例代碼
這篇文章主要介紹了echarts實(shí)現(xiàn)詞云自定義形狀的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-02-02JS實(shí)現(xiàn)轉(zhuǎn)動(dòng)隨機(jī)數(shù)抽獎(jiǎng)特效代碼
這篇文章主要為大家詳細(xì)介紹了一款轉(zhuǎn)動(dòng)隨機(jī)數(shù)抽獎(jiǎng)的JS特效代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-08-08BootStrap 圖片樣式、輔助類樣式和CSS組件的實(shí)例詳解
這篇文章主要介紹了BootStrap 圖片樣式、輔助類樣式和CSS組件的實(shí)現(xiàn)代碼,圖文并茂介紹的非常詳細(xì),需要的朋友參考下吧2017-01-01javascript js 操作數(shù)組 增刪改查的簡(jiǎn)單實(shí)現(xiàn)
下面小編就為大家?guī)?lái)一篇javascript js 操作數(shù)組 增刪改查的簡(jiǎn)單實(shí)現(xiàn)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-06Bootstrap CSS組件之下拉菜單(dropdown)
這篇文章主要為大家詳細(xì)介紹了Bootstrap CSS組件之下拉菜單(dropdown),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12基于javascript實(shí)現(xiàn)表格的簡(jiǎn)單操作
這篇文章主要為大家詳細(xì)介紹了基于javascript實(shí)現(xiàn)表格的簡(jiǎn)單操作,具有一定的參考價(jià)值,感興趣的朋友可以參考一下2016-05-05