国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

iscroll.js的上拉下拉刷新時無法回彈的解決方法

2019-11-20 10:34:22
字體:
供稿:網(wǎng)友

使用過iscroll.js的上拉下拉刷新效果的朋友應(yīng)該都碰到過這個問題:在iOS的瀏覽器中,上拉或下拉刷新時,當(dāng)手指劃出屏幕后,頁面無法彈回。很多人因為解決不了這個問題,干脆就那樣不解決了,還有的直接就不用HTML了,使用原生代替HTML頁面。

相信很多朋友也有自己的解決辦法,只是沒寫出來,所以網(wǎng)上都搜不到解決方案。在很多QQ群里面也有很多人在問該怎么解決這個問題,所以我寫這篇文章記錄一下我的解決方案,希望對一些朋友有所幫助。

上拉下拉刷新的主要代碼:

 myScroll = new iScroll('wrapper', {  vScrollbar: false,  useTransition: true,  topOffset: pullDownOffset,  onRefresh: function () {   if (pullDownEl.className.match('loading')) {    pullDownEl.className = '';    pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Pull down to refresh...';   } else if (pullUpEl.className.match('loading')) {    pullUpEl.className = '';    pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Pull up to load more...';   }  },  onScrollMove: function () {   if (this.y > 5 && !pullDownEl.className.match('flip')) {    pullDownEl.className = 'flip';    pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Release to refresh...';    this.minScrollY = 0;   } else if (this.y < 5 && pullDownEl.className.match('flip')) {    pullDownEl.className = '';    pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Pull down to refresh...';    this.minScrollY = -pullDownOffset;   } else if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match('flip')) {    pullUpEl.className = 'flip';    pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Release to refresh...';    this.maxScrollY = this.maxScrollY;   } else if (this.y > (this.maxScrollY + 5) && pullUpEl.className.match('flip')) {    pullUpEl.className = '';    pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Pull up to load more...';    this.maxScrollY = pullUpOffset;   }  },  onScrollEnd: function () {   if (pullDownEl.className.match('flip')) {    pullDownEl.className = 'loading';    pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Loading...';    pullDownAction();   } else if (pullUpEl.className.match('flip')) {    pullUpEl.className = 'loading';    pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Loading...';    pullUpAction();   }  } });

頁面無法彈回的原因在于:手指劃出屏幕后touchend事件無法觸發(fā),回彈動畫就無法執(zhí)行。解決辦法就是:當(dāng)手指接近屏幕邊緣的時候,手動觸發(fā)動畫方法。

在onScrollMove方法中插入判斷代碼:

  onScrollMove: function () {   if((this.y < this.maxScrollY) && (this.pointY < 1)){    this.scrollTo(0, this.maxScrollY, 400);    return;   } else if (this.y > 0 && (this.pointY > window.innerHeight - 1)) {    this.scrollTo(0, 0, 400);    return;   }   ......  }

下面解釋一下這段代碼的意思。

this.y是頁面已經(jīng)滾動的垂直距離,this.maxScrollY是最大垂直滾動距離,this.pointY手指當(dāng)前的垂直坐標(biāo)。

當(dāng)this.y < this.maxScrollY,就是已經(jīng)處于上拉的過程,當(dāng)(this.y < this.maxScrollY) && (this.pointY < 1)時,處于上拉且手指已經(jīng)觸及屏幕邊緣,這時候手動觸發(fā)this.scrollTo(0, this.maxScrollY, 400),頁面就開始回彈。

下拉過程也可以同理分析。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 玛曲县| 黔西| 民权县| 泗水县| 新丰县| 运城市| 尉犁县| 方正县| 旺苍县| 罗甸县| 邛崃市| 东兰县| 长子县| 井冈山市| 永吉县| 买车| 三门县| 耿马| 呼玛县| 筠连县| 西峡县| 班戈县| 民勤县| 平乐县| 武邑县| 宣威市| 濮阳市| 乐业县| 贵南县| 岑巩县| 博客| 灵丘县| 合肥市| 湾仔区| 蒙阴县| 柳州市| 泰来县| 公安县| 柳河县| 乌兰县| 栾川县|