【体验优化】手机浏览器中下拉显示网址问题(主要是IOS下需要这样处理)

let isScroll = false,
  touchSX, //触摸开始的X坐标
  touchSY, //触摸开始的Y坐标
  touchEX, //触摸结束的X坐标
  touchEY, //触摸结束的Y坐标
  touchSEX, //一次触摸的X坐标差
  touchSEY; //一次触摸的Y坐标差
$("body").on('touchstart', ".event-phoneScroll", function (e) {
  let el = $(this)[0],
    touches = e.touches[0];
  touchSX = touches.pageX;
  touchSY = touches.pageY;
  if (el.scrollTop === 0 || (el.scrollTop + el.offsetHeight) === el.scrollHeight) {
    isScroll = false;
  }
}).on('touchmove', ".event-phoneScroll", function (e) {
  let el = $(this)[0],
    touches = e.touches[0];
  touchEX = touches.pageX;
  touchEY = touches.pageY;

  touchSEX = touchEX - touchSX;
  touchSEY = touchEY - touchSY;
  let slidingType = "";
  if (Math.abs(touchSEX) > 10 || Math.abs(touchSEY) > 10) {
    if (Math.abs(touchSEX) > Math.abs(touchSEY)) {
      if (touchSEX > 0) {
        slidingType = "right";
      } else {
        slidingType = "left";
      }
      isScroll = true;
    } else {

      if (touchSEY > 0) {
        slidingType = "down";
      } else {
        slidingType = "up";
      }
      if (el.scrollTop === 0 && (slidingType === "" || slidingType === "down")) {
        isScroll = false;
      } else if ((el.scrollTop + el.offsetHeight) === el.scrollHeight && (slidingType === "" || slidingType === "up")) {
        isScroll = false;
      } else {
        isScroll = true;
      }
    }
  }
});
document.body.addEventListener('touchmove', function (e) {
  if (!isScroll) {
    e.preventDefault();
  }
}, {passive: false});

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值