touchaction.html 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="viewport" content="width=device-width">
  5. <link rel="stylesheet" href="assets/style.css">
  6. <title>Hammer.js</title>
  7. <style>
  8. .tester {
  9. margin: 20px 0;
  10. padding: 10px;
  11. height: 200px;
  12. overflow: hidden;
  13. }
  14. .scroll-space {
  15. height: 9000px;
  16. }
  17. #native, #no-native {
  18. color: #fff;
  19. font-weight: bold;
  20. font-size: 1.1em;
  21. padding: 10px 20px;
  22. display: none;
  23. margin: 25px 0;
  24. }
  25. .show {
  26. display: block !important;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <div class="container">
  32. <p>Hammer provides a <a href="../../src/touchaction.js">kind of polyfill</a>
  33. for the browsers that don't support the <a href="http://www.w3.org/TR/pointerevents/#the-touch-action-css-property">touch-action</a> property.</p>
  34. <div id="native" class="green">Your browser has support for the touch-action property!</div>
  35. <div id="no-native" class="red">Your browser doesn't support the touch-action property,
  36. so we use the polyfill.</div>
  37. <h2>touch-action: auto</h2>
  38. <p>Should prevent nothing.</p>
  39. <div class="tester azure" id="auto"></div>
  40. <h2>touch-action: pan-y</h2>
  41. <p>Should prevent scrolling on horizontal movement. This is set by default when creating a Hammer instance.</p>
  42. <div class="tester azure" id="pan-y"></div>
  43. <h2>touch-action: pan-x</h2>
  44. <p>Should prevent scrolling on vertical movement.</p>
  45. <div class="tester azure" id="pan-x"></div>
  46. <h2>touch-action: pan-x pan-y</h2>
  47. <p>Should <strong>not</strong> prevent any scrolling on any movement. Horizontal and vertical scrolling handled by the browser directly.</p>
  48. <div class="tester azure" id="pan-x-pan-y"></div>
  49. <h2>touch-action: none</h2>
  50. <p>Should prevent all.</p>
  51. <div class="tester azure" id="none"></div>
  52. </div>
  53. <script src="../../hammer.js"></script>
  54. <script>
  55. var support = Hammer.prefixed(document.body.style, 'touchAction');
  56. document.getElementById(support ? 'native' : 'no-native').className += ' show';
  57. var touchActions = ['auto', 'pan-y', 'pan-x', 'pan-x pan-y', 'none'];
  58. Hammer.each(touchActions, function(touchAction) {
  59. var el = document.getElementById(touchAction.replace(" ", "-"));
  60. var mc = Hammer(el, {
  61. touchAction: touchAction
  62. });
  63. mc.get('pan').set({ direction: Hammer.DIRECTION_ALL });
  64. mc.get('pinch').set({ enable: true });
  65. mc.get('rotate').set({ enable: true });
  66. mc.on("pan swipe rotate pinch tap doubletap press", function(ev) {
  67. el.textContent = ev.type +" "+ el.textContent;
  68. });
  69. });
  70. </script>
  71. <div class="scroll-space"></div>
  72. <p>hi.</p>
  73. </body>
  74. </html>