input.html 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. <meta name="msapplication-tap-highlight" content="no"/>
  7. <link rel="stylesheet" href="assets/style.css">
  8. <title>Hammer.js</title>
  9. </head>
  10. <body>
  11. <div class="container">
  12. <div id="hit" class="bg1" style="padding: 30px; height: 200px;">
  13. </div>
  14. <pre id="debug" style="overflow:hidden; background: #eee; padding: 15px;"></pre>
  15. <pre id="log" style="overflow:hidden;"></pre>
  16. </div>
  17. <script src="../../hammer.js"></script>
  18. <script>
  19. Object.prototype.toDirString = function() {
  20. var output = [];
  21. for(var key in this) {
  22. if(this.hasOwnProperty(key)) {
  23. var value = this[key];
  24. if(Array.isArray(value)) {
  25. value = "Array("+ value.length +"):"+ value;
  26. } else if(value instanceof HTMLElement) {
  27. value = value +" ("+ value.outerHTML.substring(0, 50) +"...)";
  28. }
  29. output.push(key +": "+ value);
  30. }
  31. }
  32. return output.join("\n")
  33. };
  34. var el = document.querySelector("#hit");
  35. var log = document.querySelector("#log");
  36. var debug = document.querySelector("#debug");
  37. var mc = new Hammer(el);
  38. mc.get('pinch').set({ enable: true });
  39. mc.on("hammer.input", function(ev) {
  40. debug.innerHTML = [ev.srcEvent.type, ev.pointers.length, ev.isFinal, ev.deltaX, ev.deltaY].join("<br>");
  41. });
  42. </script>
  43. </body>
  44. </html>