Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. window.onload = function() {
  2. (function(d) {
  3. var
  4. ce = function(e, n) {
  5. var a = document.createEvent("CustomEvent");
  6. a.initCustomEvent(n, true, true, e.target);
  7. e.target.dispatchEvent(a);
  8. a = null;
  9. return false
  10. },
  11. nm = true,
  12. sp = {
  13. x: 0,
  14. y: 0
  15. },
  16. ep = {
  17. x: 0,
  18. y: 0
  19. },
  20. touch = {
  21. touchstart: function(e) {
  22. sp = {
  23. x: e.touches[0].pageX,
  24. y: e.touches[0].pageY
  25. }
  26. },
  27. touchmove: function(e) {
  28. nm = false;
  29. ep = {
  30. x: e.touches[0].pageX,
  31. y: e.touches[0].pageY
  32. }
  33. },
  34. touchend: function(e) {
  35. if (nm) {
  36. ce(e, 'fc')
  37. } else {
  38. var x = ep.x - sp.x,
  39. xr = Math.abs(x),
  40. y = ep.y - sp.y,
  41. yr = Math.abs(y);
  42. if (Math.max(xr, yr) > 20) {
  43. ce(e, (xr > yr ? (x < 0 ? 'swl' : 'swr') : (y < 0 ? 'swu' : 'swd')))
  44. }
  45. };
  46. nm = true
  47. },
  48. touchcancel: function(e) {
  49. nm = false
  50. }
  51. };
  52. for (var a in touch) {
  53. d.addEventListener(a, touch[a], false);
  54. }
  55. })(document);
  56. //EXAMPLE OF USE
  57. var h = function(e) {
  58. console.log(e.type, e)
  59. };
  60. document.body.addEventListener('fc', h, false); // 0-50ms vs 500ms with normal click
  61. document.body.addEventListener('swl', h, false);
  62. document.body.addEventListener('swr', h, false);
  63. document.body.addEventListener('swu', h, false);
  64. document.body.addEventListener('swd', h, false);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement