-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathtouch-action.html
103 lines (103 loc) · 2.8 KB
/
touch-action.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
<!DOCTYPE html>
<html>
<head>
<title>Touch-action demo page</title>
<style>
body, html {
height: 100%;
width: 100%;
margin: 0;
}
#spacer {
width: 2000px;
height: 2000px;
}
#targets {
font-size: 30px;
padding-top: 100px;
padding-left: 50px;
overflow: scroll;
width: 90%;
height: 45%;
}
.block {
display: inline-block;
box-sizing: border-box;
margin: 10px;
width: 250px;
height: 250px;
background-color: lightblue;
border: 1px solid black;
text-align: center;
padding-top: 40px;
}
#log {
margin: 5px;
border: 1px solid black;
overflow: scroll;
height: 40%;
}
.block.nosupport {
background-color: red;
}
.block.nosupport::after {
content: "\aNOT SUPPORTED";
white-space: pre;
}
</style>
</head>
<body>
<div id=targets>
<div class='block nosupport' action='auto' onclick="">auto</div>
<div class='block nosupport' action='none' onclick="">none</div>
<div class='block nosupport' action='pan-x' onclick="">pan-x</div>
<div class='block nosupport' action='pan-y' onclick="">pan-y</div>
<div class='block nosupport' action='pan-x pan-y' onclick="">pan-x pan-y</div>
<div class='block nosupport' action='manipulation' onclick="">manipulation</div>
<div class='block nosupport' action='pan-left' onclick="">pan-left</div>
<div class='block nosupport' action='pan-right' onclick="">pan-right</div>
<div class='block nosupport' action='pan-up' onclick="">pan-up</div>
<div class='block nosupport' action='pan-down' onclick="">pan-down</div>
<div class='block nosupport' action='pinch-zoom' onclick="">pinch-zoom</div>
<div id=spacer>
</div>
</div>
<div id=log>
</div>
<script>
function log(msg) {
document.getElementById('log').innerHTML += msg + '<br/>';
}
var lastTime = undefined;
function handler(event) {
if ((event.type == 'touchstart' && event.touches.length == event.changedTouches.length) ||
(event.type == 'pointerdown' && event.isPrimary)) {
document.getElementById('log').innerHTML = '';
}
var msg = event.type;
if (event.cancelable)
msg += ' cancelable';
if (lastTime && event.timeStamp)
msg += ' ' + (event.timeStamp - lastTime) + 'ms';
log(msg);
lastTime = event.timeStamp;
}
var events = ['touchstart', 'touchmove', 'touchend', 'touchcancel',
'pointerdown', 'pointermove', 'pointerup', 'pointerenter', 'pointerleave', 'pointercancel',
'click' ];
events.forEach(function(name) {
document.getElementById('targets').addEventListener(name, handler);
});
var blocks = document.querySelectorAll('.block');
for (var i = 0; i < blocks.length; i++) {
var elem = blocks[i];
var action = elem.getAttribute('action');
if ('touchAction' in elem.style) {
elem.style.touchAction = action;
if (elem.style.touchAction == action)
elem.classList.remove('nosupport');
}
}
</script>
</body>
</html>