移动端滑动方向

2019-07-15  本文已影响0人  丸子_d7e2
      //滑动处理
      var startX, startY, moveEndX, moveEndY, X, Y;
      mybody.addEventListener('touchstart', function(e) {
        startX = e.touches[0].pageX;
        startY = e.touches[0].pageY;
      });
      mybody.addEventListener('touchmove', function(e) {
        moveEndX = e.changedTouches[0].pageX;
        moveEndY = e.changedTouches[0].pageY;
        X = moveEndX - startX;
        Y = moveEndY - startY;
        if (X > 0 && Math.abs(X) > Math.abs(Y)) {
          that.showProgessFlag = true;
        } else if (X < 0 && Math.abs(X) > Math.abs(Y)) {
          that.showProgessFlag = true;
        } else if (Y > 0 && Math.abs(Y) > Math.abs(X)) {
          that.showProgessFlag = true;
        } else if (Y < 0 && Math.abs(Y) > Math.abs(X)) {
          that.showProgessFlag = true;
        } else {
          that.showProgessFlag = true;
        }
      });
上一篇 下一篇

猜你喜欢

热点阅读