touchmove.wxs 734 B

1234567891011121314151617181920212223242526272829303132
  1. var touchStart
  2. function handleTouchStart(event) {
  3. touchStart = event.changedTouches[0].clientX
  4. }
  5. function handleTouchEnd(event, ownerInstance) {
  6. var touchEndX = event.changedTouches[0].clientX
  7. var distance = touchEndX - touchStart
  8. // -1:后退;0:不动;1:前进
  9. var direction = 0
  10. // 向左滑,前进
  11. if (distance < 0 && distance < -70) {
  12. direction = 1
  13. }
  14. // 向右滑,后退
  15. if (distance > 0 && distance > 70) {
  16. direction = -1
  17. }
  18. if (direction !== 0) {
  19. ownerInstance.callMethod('handleTouchmove', {direction: direction})
  20. }
  21. touchStart = 0
  22. }
  23. module.exports = {
  24. handleTouchStart: handleTouchStart,
  25. handleTouchEnd: handleTouchEnd
  26. }