|
| 1 | +<!DOCTYPE html> |
| 2 | +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 3 | + <head> |
| 4 | + <meta http-equiv="X-UA-Compatible" content="IE=10; IE=9; IE=8;" /> |
| 5 | + <meta name="robots" content="index,follow" /> |
| 6 | + <title>Test with scrollable element</title> |
| 7 | + <script type="text/javascript" src="js/touchr.js"></script> |
| 8 | + |
| 9 | + <!-- Modernizr.touch should be true --> |
| 10 | + <!-- script type="text/javascript" src="http://modernizr.com/downloads/modernizr-latest.js"></script--> |
| 11 | + <style type="text/css"> |
| 12 | + html { |
| 13 | + overflow: hidden; |
| 14 | + } |
| 15 | + body { |
| 16 | + margin: 0; |
| 17 | + padding: 0; |
| 18 | + width: 100%; |
| 19 | + height: 100%; |
| 20 | + -ms-touch-action: none; |
| 21 | + touch-action: none; |
| 22 | + position: absolute; |
| 23 | + } |
| 24 | + |
| 25 | + /* Log window */ |
| 26 | + #log { |
| 27 | + position: absolute; |
| 28 | + overflow: auto; |
| 29 | + width: 400px; |
| 30 | + height: 100%; |
| 31 | + left: 0; |
| 32 | + font-family: Consolas; |
| 33 | + font-size: 12px; |
| 34 | + } |
| 35 | + |
| 36 | + #clear { |
| 37 | + position:absolute; |
| 38 | + left: 400px; |
| 39 | + } |
| 40 | + |
| 41 | + #logHead { |
| 42 | + font-weight: bold; |
| 43 | + } |
| 44 | + #logContent { |
| 45 | + white-space: pre; |
| 46 | + } |
| 47 | + </style> |
| 48 | + |
| 49 | + </head> |
| 50 | + <body id="body"> |
| 51 | + <div id="x" style="width: 200px; height: 200px; overflow-y: scroll;"> |
| 52 | + <div id="in" style="height: 1000px"></div> |
| 53 | + </div> |
| 54 | + |
| 55 | + <div id="log"> |
| 56 | + <div id="logHead">type, touches#, changed#, [0]screenX/Y, [1]screenX/Y</div> |
| 57 | + <div id="logContent"></div> |
| 58 | + </div> |
| 59 | + |
| 60 | + <button id="clear" onclick="document.getElementById('logContent').innerText='';">Clear</button> |
| 61 | + |
| 62 | + <script type="text/javascript"> |
| 63 | + //logging |
| 64 | + var logdiv = document.getElementById("logContent"); |
| 65 | + |
| 66 | + function log() { |
| 67 | + var txt = document.createTextNode(Array.prototype.join.call(arguments, ", ") + "\r\n"); |
| 68 | + logdiv.insertBefore(txt, logdiv.firstChild); |
| 69 | + } |
| 70 | + |
| 71 | + function listener(e) { |
| 72 | + var len = e.touches ? e.touches.length : 0; |
| 73 | + log( |
| 74 | + e.type, |
| 75 | + len ? len : 0, |
| 76 | + e.changedTouches ? e.changedTouches.length : "-", |
| 77 | + e.target.nodeName+"#"+e.target.id, |
| 78 | + len > 0 ? e.touches[0].screenX : "-", |
| 79 | + len > 0 ? e.touches[0].screenY : "-", |
| 80 | + len > 1 ? e.touches[1].screenX : "-", |
| 81 | + len > 1 ? e.touches[1].screenY : "-" |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + // Triggering the events for this element |
| 86 | + var elm = document.body; |
| 87 | + |
| 88 | + elm.addEventListener("touchstart", listener, false); |
| 89 | + elm.addEventListener("touchmove", listener, false); |
| 90 | + elm.addEventListener("touchend", listener, false); |
| 91 | + |
| 92 | + elm.addEventListener("gesturestart", listener, false); |
| 93 | + elm.addEventListener("gesturechange", listener, false); |
| 94 | + elm.addEventListener("gestureend", listener, false); |
| 95 | + </script> |
| 96 | + |
| 97 | + </body> |
| 98 | +</html> |
0 commit comments