touch.js 889B

12345678910111213141516171819202122232425262728
  1. export const touch = Behavior({
  2. methods: {
  3. touchStart(event) {
  4. const touch = event.touches[0];
  5. this.direction = '';
  6. this.deltaX = 0;
  7. this.deltaY = 0;
  8. this.offsetX = 0;
  9. this.offsetY = 0;
  10. this.startX = touch.clientX;
  11. this.startY = touch.clientY;
  12. },
  13. touchMove(event) {
  14. const touch = event.touches[0];
  15. this.deltaX = touch.clientX - this.startX;
  16. this.deltaY = touch.clientY - this.startY;
  17. this.offsetX = Math.abs(this.deltaX);
  18. this.offsetY = Math.abs(this.deltaY);
  19. this.direction =
  20. this.offsetX > this.offsetY
  21. ? 'horizontal'
  22. : this.offsetX < this.offsetY
  23. ? 'vertical'
  24. : '';
  25. }
  26. }
  27. });