iscroll.js的上拉下拉刷新时无法回弹的解决方法

在ios中,部分操作下界面无法回弹。导致界面卡在上面。

页面无法弹回的原因:手指划出屏幕后touchend事件无法触发,回弹动画就无法执行。

解决办法:当手指接近屏幕边缘的时候,手动触发动画方法。


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

this.y是页面已经滚动的垂直距离,this.maxScrollY是最大垂直滚动距离,this.pointY手指当前的垂直坐标。

当this.y < this.maxScrollY,就是已经处于上拉的过程,当(this.y < this.maxScrollY) && (this.pointY < 1)时,处于上拉且手指已经触及屏幕边缘,这时候手动触发this.scrollTo(0, this.maxScrollY, 400),页面就开始回弹。

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


下拉刷新、上拉加载监控完整代码块:

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();
  }
 }
});



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值