touch.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. exports.touch = void 0;
  4. var MIN_DISTANCE = 10;
  5. function getDirection(x, y) {
  6. if (x > y && x > MIN_DISTANCE) {
  7. return 'horizontal';
  8. }
  9. if (y > x && y > MIN_DISTANCE) {
  10. return 'vertical';
  11. }
  12. return '';
  13. }
  14. exports.touch = Behavior({
  15. methods: {
  16. resetTouchStatus: function () {
  17. this.direction = '';
  18. this.deltaX = 0;
  19. this.deltaY = 0;
  20. this.offsetX = 0;
  21. this.offsetY = 0;
  22. },
  23. touchStart: function (event) {
  24. this.resetTouchStatus();
  25. var touch = event.touches[0];
  26. this.startX = touch.clientX;
  27. this.startY = touch.clientY;
  28. },
  29. touchMove: function (event) {
  30. var touch = event.touches[0];
  31. this.deltaX = touch.clientX - this.startX;
  32. this.deltaY = touch.clientY - this.startY;
  33. this.offsetX = Math.abs(this.deltaX);
  34. this.offsetY = Math.abs(this.deltaY);
  35. this.direction =
  36. this.direction || getDirection(this.offsetX, this.offsetY);
  37. },
  38. },
  39. });