-
Notifications
You must be signed in to change notification settings - Fork 1
/
showevent.html
134 lines (119 loc) · 3.81 KB
/
showevent.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<html>
<head>
<meta charset="utf-8">
<script>
document.addEventListener("DOMContentLoaded", function(event) {
var tapup
, tapdown
, tapinfo
, mouseup
, mousedown
, mouseinfo
;
tapup = document.getElementById("tapup");
tapdown = document.getElementById("tapdown");
tapdowninfo = document.getElementById("tapdowninfo");
tapupinfo = document.getElementById("tapupinfo");
mouseup = document.getElementById("mouseup");
mousedown = document.getElementById("mousedown");
mousedowninfo = document.getElementById("mousedowninfo");
mouseupinfo = document.getElementById("mouseupinfo");
document.addEventListener("touchstart", createTapCallback(tapdown, tapdowninfo), false);
document.addEventListener("touchend", createTapCallback(tapup, tapupinfo), false);
document.addEventListener("mousedown", createMouseCallback(mousedown, mousedowninfo), false);
document.addEventListener("mouseup", createMouseCallback(mouseup, mouseupinfo), false);
});
function updateInfo(info, data) {
info.innerHTML = "P:(" + data.pageX + ", " + data.pageY + ") C:(" + data.clientX + ", " + data.clientY + ")";
}
function createTapCallback(el, info) {
var offset = el.offsetHeight / 2;
return function(evt) {
var touches = evt.changedTouches;
if (touches.length > 0) {
// tap.html("T: page(" + touches[0].pageX.toString() + ", " + touches[0].pageY.toString() + ") client("
// + touches[0].clientX.toString() + ", " + touches[0].clientY.toString() + ")");
el.style.visibility = "visible";
el.style.top = (touches[0].pageY - offset).toString() + "px";
el.style.left = (touches[0].pageX - offset).toString() + "px";
updateInfo(info, touches[0]);
}
};
}
function createMouseCallback(el, info) {
var offset = el.offsetHeight / 2;
return function(evt) {
// tap.html("T: page(" + touches[0].pageX.toString() + ", " + touches[0].pageY.toString() + ") client("
// + touches[0].clientX.toString() + ", " + touches[0].clientY.toString() + ")");
el.style.visibility = "visible";
el.style.top = (evt.pageY - offset).toString() + "px";
el.style.left = (evt.pageX - offset).toString() + "px";
updateInfo(info, evt);
};
}
</script>
<style type="text/css">
body {
background-color: white;
}
.inline {
display: inline-block;
font-family: monospace;
}
#info {
z-index: 6;
display: inline-block;
position: fixed;
bottom: 5px;
}
#tapup, #tapdown, #mouseup, #mousedown {
display: inline-block;
visibility: hidden;
position: absolute;
top: 20px;
left: 30px;
margin: 0 auto;
}
#tapup {
z-index: 5;
background-color: rgb(255, 0, 0);
width: 20px;
height: 20px;
}
#tapdown {
z-index: 4;
background-color: rgb(100, 100, 255);
width: 30px;
height: 30px;
}
#mouseup {
z-index: 3;
background-color: rgb(0, 255, 0);
width: 40px;
height: 40px;
}
#mousedown {
z-index: 2;
background-color: rgb(127, 127, 127);
width: 50px;
height: 50px;
}
</style>
</head>
<body>
<div class="inline" id="info">
<div style="background-color: rgb(127,127,127); display: inline-block;"> </div>
Down Mouse: <div class="inline" id="mousedowninfo">None</div><br>
<div style="background-color: rgb(0,255,0); display: inline-block;"> </div>
Up Mouse: <div class="inline" id="mouseupinfo">None</div><br>
<div style="background-color: rgb(100,100,255); display: inline-block;"> </div>
Down Tap: <div class="inline" id="tapdowninfo">None</div><br>
<div style="background-color: rgb(255,0,0); display: inline-block;"> </div>
Up Tap: <div class="inline" id="tapupinfo">None</div>
</div>
<div id="mouseup"></div>
<div id="mousedown"></div>
<div id="tapdown"></div>
<div id="tapup"></div>
</body>
</html>