touch.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.TouchMixin = 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. var TouchMixin = {
  15. data: function data() {
  16. return {
  17. direction: ''
  18. };
  19. },
  20. methods: {
  21. touchStart: function touchStart(event) {
  22. this.resetTouchStatus();
  23. this.startX = event.touches[0].clientX;
  24. this.startY = event.touches[0].clientY;
  25. },
  26. touchMove: function touchMove(event) {
  27. var touch = event.touches[0];
  28. this.deltaX = touch.clientX - this.startX;
  29. this.deltaY = touch.clientY - this.startY;
  30. this.offsetX = Math.abs(this.deltaX);
  31. this.offsetY = Math.abs(this.deltaY);
  32. this.direction = this.direction || getDirection(this.offsetX, this.offsetY);
  33. },
  34. resetTouchStatus: function resetTouchStatus() {
  35. this.direction = '';
  36. this.deltaX = 0;
  37. this.deltaY = 0;
  38. this.offsetX = 0;
  39. this.offsetY = 0;
  40. }
  41. }
  42. };
  43. exports.TouchMixin = TouchMixin;