touch.js 1.1 KB

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