swipe.js 896 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * @name Swipe Module
  3. * @description Swipes and moves an object.
  4. * @author Tobias Reich
  5. * @copyright 2014 by Tobias Reich
  6. */
  7. swipe = {
  8. obj: null,
  9. tolerance: 150,
  10. start: function(obj, tolerance) {
  11. console.log('start with ' + obj);
  12. if (obj) swipe.obj = obj;
  13. if (tolerance) swipe.tolerance = tolerance;
  14. return true;
  15. },
  16. move: function(e) {
  17. console.log(e);
  18. e.x *= -1;
  19. swipe.obj.css({
  20. WebkitTransform: 'translateX(' + e.x + 'px)',
  21. MozTransform: 'translateX(' + e.x + 'px)',
  22. transform: 'translateX(' + e.x + 'px)'
  23. });
  24. },
  25. stop: function(e, left, right) {
  26. console.log('stop with ' + e.x);
  27. if (e.x<=-150) left();
  28. else if (e.x>=150) right();
  29. else {
  30. console.log('reset');
  31. swipe.obj.css({
  32. WebkitTransform: 'translateX(0px)',
  33. MozTransform: 'translateX(0px)',
  34. transform: 'translateX(0px)'
  35. });
  36. }
  37. swipe.obj = null;
  38. }
  39. };