[OpenLayers-Commits] r11666 - sandbox/tschaub/click/examples

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Tue Mar 8 02:43:33 EST 2011


Author: tschaub
Date: 2011-03-07 23:43:32 -0800 (Mon, 07 Mar 2011)
New Revision: 11666

Added:
   sandbox/tschaub/click/examples/dpx.html
Log:
Adding example to display pixel displacement between taps.

Added: sandbox/tschaub/click/examples/dpx.html
===================================================================
--- sandbox/tschaub/click/examples/dpx.html	                        (rev 0)
+++ sandbox/tschaub/click/examples/dpx.html	2011-03-08 07:43:32 UTC (rev 11666)
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <title>dpx</title>
+        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0;">
+        <style>
+            html, body {
+                height: 100%;
+                margin: 0;
+            }
+            #target {
+                width: 100%;
+                height: 100%;
+                background: #ccc;
+                font-size: 3em;
+                text-align: center;
+            }
+        </style>
+    </head>
+    <body>
+        <div id="target">tap twice</div>
+        <script>
+            var counter = 0;
+            var x, y;
+            var target = document.getElementById("target");
+            function down(evt) {
+                var newX = evt.touches && evt.touches[0].clientX || evt.clientX;
+                var newY = evt.touches && evt.touches[0].clientY || evt.clientY;
+                if (typeof x !== "number") {
+                    x = newX;
+                    y = newY;
+                } else {
+                    ++counter;
+                    target.innerHTML = "pair " + counter + ": " + 
+                        (Math.sqrt(
+                            Math.pow(x - newX, 2) +
+                            Math.pow(y - newY, 2)
+                        ) | 0);
+                    x = null;
+                    y = null;
+                }
+                evt.preventDefault();
+            }
+            target.addEventListener("touchstart", down, false);
+            target.addEventListener("mousedown", down, false);
+        </script>
+    </body>
+</html>



More information about the Commits mailing list