multiple.html 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
  6. <link rel="stylesheet" href="assets/style.css">
  7. <title>Hammer.js</title>
  8. <style>
  9. #right,
  10. #left {
  11. display: block;
  12. width: 50%;
  13. height: 500px;
  14. overflow: hidden;
  15. }
  16. #left { float: left; }
  17. #right { float: right; }
  18. </style>
  19. </head>
  20. <body>
  21. <div class="container">
  22. <pre id="left" class="bg1"></pre>
  23. <pre id="right" class="bg5"></pre>
  24. <div class="clear"></div>
  25. <h1>Multiple instances the same time</h1>
  26. <p>You can run multiple instances of Hammer on your page and they will recognize each completely isolated
  27. from each other. This makes it possible to build multi-user interfaces.</p>
  28. </div>
  29. <script src="../../hammer.min.js"></script>
  30. <script>
  31. Object.prototype.toDirString = function() {
  32. var output = [];
  33. for(var key in this) {
  34. if(this.hasOwnProperty(key)) {
  35. var value = this[key];
  36. if(Array.isArray(value)) {
  37. value = "Array("+ value.length +"):"+ value;
  38. } else if(value instanceof HTMLElement) {
  39. value = value +" ("+ value.outerHTML.substring(0, 50) +"...)";
  40. }
  41. output.push(key +": "+ value);
  42. }
  43. }
  44. return output.join("\n")
  45. };
  46. function addHammer(el) {
  47. var mc = new Hammer(el, { multiUser: true });
  48. mc.get('pan').set({ direction: Hammer.DIRECTION_ALL });
  49. mc.get('swipe').set({ direction: Hammer.DIRECTION_ALL });
  50. mc.get('pinch').set({ enable: true });
  51. mc.get('rotate').set({ enable: true });
  52. mc.on("swipe pan press pinch rotate tap doubletap", function (ev) {
  53. ev.preventDefault();
  54. el.innerText = ev.toDirString();
  55. });
  56. }
  57. addHammer(document.querySelector("#left"));
  58. addHammer(document.querySelector("#right"));
  59. </script>
  60. </body>
  61. </html>