【体验优化】手机浏览器中下拉显示网址问题(主要是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});

 

你可能感兴趣的:(【体验优化】手机浏览器中下拉显示网址问题(主要是IOS下需要这样处理))