touch.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Zepto touch functional test</title>
  6. <meta name="viewport" content="maximum-scale=1,initial-scale=1,user-scalable=0">
  7. <link rel="stylesheet" href="../test.css">
  8. <script src="../../src/zepto.js"></script>
  9. <script src="../../src/event.js"></script>
  10. <script src="../../src/ie.js"></script>
  11. <script src="../../src/touch.js"></script>
  12. </head>
  13. <body>
  14. <h1>Zepto touch functional test</h1>
  15. <p>
  16. Browser supports touch events?
  17. <script>document.write('ontouchstart' in window)</script><br>
  18. Browser supports MS pointer events?
  19. <script>document.write(!!navigator.msPointerEnabled)</script>
  20. </p>
  21. <div id="touch_test" style="width: 200px; height: 200px; background: #cce; -webkit-user-select: none">
  22. touch events test
  23. </div>
  24. <div id='touch_test_scrollable' style="width: 200px; height: 200px; background: #cec; -webkit-user-select: none">
  25. touch events test (scrollable cancel)
  26. </div>
  27. <div id='touch_test_single' style="width: 200px; height: 200px; background: #ecc; -webkit-user-select: none">
  28. touch events test (scrollable cancel, single tap only)
  29. </div>
  30. <div id="browser"> </div>
  31. <script>
  32. $('#browser').text(navigator.userAgent)
  33. /**
  34. * #touch_test
  35. * Container that captures all touch events.
  36. *
  37. * Prevents default on touchmove, disabling scrolling.
  38. * Captures swipes in all directions.
  39. * Captures tap, singleTap (after delay), doubleTap, longTap
  40. */
  41. $('#touch_test').bind('touchmove', function(e) { e.preventDefault() })
  42. listen_to('#touch_test')
  43. /**
  44. * #touch_test_scrollable
  45. * Container that allows scrolling while capturing all events except swipes in the direction of scroll
  46. *
  47. * Captures swipes in non-scrolling directions
  48. * Captures tap, singleTap (after delay), doubleTap, longTap
  49. */
  50. listen_to('#touch_test_scrollable')
  51. /**
  52. * #touch_test_single
  53. * Container that allows scrolling and captures only simple, single taps
  54. * eg: a button or a tappable list item
  55. *
  56. * Cancels touch after tap, disabling other touch events (singleTap, doubleTap)
  57. * Captures tap
  58. */
  59. $('#touch_test_single').bind('tap', function(e) {
  60. e.cancelTouch()
  61. })
  62. listen_to('#touch_test_single')
  63. function listen_to(el) {
  64. $(el).tap(function(){
  65. $(this).append(' | tap!')
  66. })
  67. .doubleTap(function(){
  68. $(this).append(' | double tap!')
  69. })
  70. .swipe(function(){
  71. $(this).append(' | swipe!')
  72. })
  73. .swipeLeft(function(){
  74. $(this).append(' | swipe left!')
  75. })
  76. .swipeRight(function(){
  77. $(this).append(' | swipe right!')
  78. })
  79. .swipeUp(function(){
  80. $(this).append(' | swipe up!')
  81. })
  82. .swipeDown(function(){
  83. $(this).append(' | swipe down!')
  84. })
  85. .longTap(function(){
  86. $(this).append(' | long tap!')
  87. })
  88. .singleTap(function(){
  89. $(this).append(' | single tap!')
  90. })
  91. }
  92. </script>
  93. </body>
  94. </html>