Guest User

Untitled

a guest
Feb 25th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. var swiper = {
  2.  
  3. touchStartX: 0,
  4. touchEndX: 0,
  5. minSwipePixels: 30,
  6. detectionZone: undefined,
  7. swiperCallback: function() {},
  8.  
  9. init: function (detectionZone, callback) {
  10. swiper.swiperCallback = callback
  11. detectionZone.addEventListener('touchstart', function (event) {
  12. swiper.touchStartX = event.changedTouches[0].screenX;
  13. }, false);
  14. detectionZone.addEventListener('touchend', function (event) {
  15. swiper.touchEndX = event.changedTouches[0].screenX;
  16. swiper.handleSwipeGesture();
  17. }, false);
  18. },
  19.  
  20. handleSwipeGesture: function () {
  21. var direction,
  22. moved
  23. if (swiper.touchEndX <= swiper.touchStartX) {
  24. moved = swiper.touchStartX - swiper.touchEndX
  25. direction = "left"
  26. }
  27. if (swiper.touchEndX >= swiper.touchStartX) {
  28. moved = swiper.touchEndX - swiper.touchStartX
  29. direction = "right"
  30. }
  31. if (moved > swiper.minSwipePixels && direction !== "undefined") {
  32. swiper.swipe(direction, moved)
  33. }
  34. },
  35.  
  36. swipe: function (direction, movedPixels) {
  37. var ret = {}
  38. ret.direction = direction
  39. ret.movedPixels = movedPixels
  40. swiper.swiperCallback(ret)
  41. }
  42. }
  43.  
  44.  
  45. //var gestureZone = document.getElementById('container');
  46. var gestureZone = document;
  47. swiper.init(gestureZone, function(e) {
  48. console.log(e)
  49. })
Add Comment
Please, Sign In to add comment