1 下載最新的iscroll5,本文版本是5.1.3javascript
2 提取iscroll-probe.js,選擇這個文件的緣由是咱們要給iscroll擴展一個事件,須要用到probeType 屬性css
3 修改iscroll-probe.js的源碼,添加上拉監聽事件slideUp (
iscroll 5 源碼註釋 http://www.ghugo.com/iscroll-5-source/)html
4 編輯頁面java
Html:app
"<div id='lookupScrollerWrapper'>"+ "<div>"+ "<div>"+ "<ul data-role='listview' id='assListId0000'></ul>"+ "</div>"+ "<div id='lookupScrollerPullUp' style='display:none'>"+ "<span>上拉加載更多</span>"+ "</div>"+ "</div>"+ "</div>"
css:ide
#lookupScrollerWrapper { position: absolute; top: 54px; bottom: 0px; width: 100%; overflow: hidden; } #lookupScrollerPullUp { height: 40px; line-height: 40px; font-size: 12px; font-weight: bold; color: grey; text-shadow: none; text-align:center; position:absolute; width:100%; bottom:-40px; }
js:this
lookupScroll = new IScroll('#lookupScrollerWrapper', { probeType: 3, mouseWheel: true, click: true }); lookupScroll.on("scroll", function() { if(this.maxScrollY - this.y >= 40){ $("#lookupScrollerPullUp").css("display", ""); } }); lookupScroll.on("slideUp", function() { if(this.maxScrollY - this.y >= 40) { this.scrollTo(0, this.maxScrollY-47, 3000, IScroll.utils.ease.back); $(this)._associateKey(); } }); $('#lookupScrollerWrapper').on('touchmove', function(){ if(lookupScroll.maxScrollY - lookupScroll.y >= 40){ $('#lookupScrollerPullUp').html("釋放加載更多"); } }); $('#lookupScrollerWrapper').on('touchend', function(){ if(lookupScroll.maxScrollY - lookupScroll.y >= 40){ $('#lookupScrollerPullUp').html("正在加載.."); } else { $('#lookupScrollerPullUp').html("上拉加載更多"); } });
6 若是頁面是動態編輯的,則要調用刷新的代碼,不然頁面不會滾動spa
lookupScroll.refresh();htm