-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
124 lines (110 loc) · 3.45 KB
/
index.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
<!DOCTYPE html>
<html id='swip'>
<head>
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1' />
<style>
body {
overscroll-behavior-y: none;
}
:root {
--Width: min(30vw, 25vh);
}
.Div {
position: relative;
width: var(--Width);
}
.Div:before {
content: "";
display: block;
padding-top: 100%;
}
.btn {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
font-size: calc(var(--Width) / 2);
}
.float {
float: left;
}
.Left {
margin-right: calc(var(--Width) / 2);
}
.Right {
margin-left: calc(var(--Width) / 2);
}
.teki {
width: calc(var(--Width) * 3);
margin: 0px auto;
}
.clear {
clear: both;
}
</style>
</head>
<body>
操作方法<br>
<input type='radio' name='sb' checked='checked' onchange='Show(true);'>ボタン</input>
<input type='radio' name='sb' onchange="Show(false);">スワイプ</input>
<br>
<div id='b'>
<center>
<div class='Div'><button class='btn' id='up'>↑</button></div><br>
<div class='teki'>
<div class='Div float Left'><button class='btn' id='left'>←</button></div>
<div class='Div float Right'><button class='btn' id='right'>→</button></div>
<div class='clear'></div>
</div><br>
<div class='Div'><button class='btn' id='down'>↓</button></div>
</center>
</div>
<script type="text/javascript">
let flg = true;
let btns = ['up', 'right', 'left', 'down'];
let btn = new Array(4);
function Show(f) {
flg = f;
if (f == true) {
document.getElementById('b').hidden = false;
} else {
document.getElementById('b').hidden = true;
}
}
function Send(dir) {
var xhr = new XMLHttpRequest();
xhr.open('GET', '?' + dir);
xhr.timeout = 1000;
xhr.setRequestHeader('Cache-Control', 'no-cache');
xhr.setRequestHeader('If-Modified-Since', 'Thu, 01 Jun 1970 00:00:00 GMT');
xhr.responseType = 'document';
xhr.ontimeout = function (e) { xhr.abort(); };
xhr.send();
}
for (let i = 0; i < 4; i++) {
btn[i] = document.getElementById(btns[i]);
btn[i].onclick = function () { Send(btns[i]) };
}
let t = document.getElementById("swip");
let sx, sy, mx, my;
t.addEventListener("touchstart", function (e) {
e.preventDefault();
sx = e.touches[0].pageX;
sy = e.touches[0].pageY;
mx = e.touches[0].pageX;
my = e.touches[0].pageY;
});
t.addEventListener("touchmove", function (e) {
e.preventDefault();
mx = e.changedTouches[0].pageX;
my = e.changedTouches[0].pageY;
});
t.addEventListener("touchend", function (e) {
let RLUD = [sy - my, mx - sx, sx - mx, my - sy, 100];
let n = RLUD.indexOf(Math.max(...RLUD));
if (!flg && n < 4) { Send(btns[n]); }
});
</script>
</body>
</html>