質問編集履歴
2
情報を追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -160,3 +160,6 @@
|
|
160
160
|
});
|
161
161
|
|
162
162
|
```
|
163
|
+
### 追記
|
164
|
+
どこか別の場所をタッチし続けておけばこのバグは発生しないことが分かりました。
|
165
|
+
恐らく他のイベントに吸われてしまっているのかと思いますが、何が原因かまでは分かりませんでした⋯
|
1
ソースコードを追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,3 +14,149 @@
|
|
14
14
|
環境はiOSで、ChromeとSafari、Firefoxでこの問題が発生しました。
|
15
15
|
自分で調べた限りではそういった仕様は見つけられませんでした。
|
16
16
|
仕様や解決策をご存知でしたら回答よろしくお願いします
|
17
|
+
|
18
|
+
### ソースコード
|
19
|
+
```HTML
|
20
|
+
|
21
|
+
<!DOCTYPE html>
|
22
|
+
<html>
|
23
|
+
<head>
|
24
|
+
<meta charset="utf-8" />
|
25
|
+
<meta name="description" content="">
|
26
|
+
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
|
27
|
+
<script type="text/javascript" src="script.js"></script>
|
28
|
+
<title>Game</title>
|
29
|
+
<style>
|
30
|
+
* {
|
31
|
+
padding: 0;
|
32
|
+
margin: 0 auto;
|
33
|
+
}
|
34
|
+
|
35
|
+
canvas {
|
36
|
+
background: #000000;
|
37
|
+
display: block;
|
38
|
+
margin: 0;
|
39
|
+
}
|
40
|
+
|
41
|
+
body {
|
42
|
+
background: #555555;
|
43
|
+
}
|
44
|
+
|
45
|
+
#Canvas {
|
46
|
+
transform-origin: top left;
|
47
|
+
transform: scale(1.0);
|
48
|
+
}
|
49
|
+
|
50
|
+
#wrapper {
|
51
|
+
width: 900px;
|
52
|
+
height: 600px;
|
53
|
+
margin: auto;
|
54
|
+
onSelectStart: "return false;";
|
55
|
+
user-select: none;
|
56
|
+
-moz-user-select: none;
|
57
|
+
-webkit-user-select: none;
|
58
|
+
-ms-user-select: none;
|
59
|
+
unselectable: "on";
|
60
|
+
}
|
61
|
+
|
62
|
+
body {
|
63
|
+
overflow: hidden;
|
64
|
+
}
|
65
|
+
</style>
|
66
|
+
</head>
|
67
|
+
<body ontouchstart="">
|
68
|
+
<div id="wrapper">
|
69
|
+
<canvas id="Canvas" width="900px" height="600px"></canvas>
|
70
|
+
</div>
|
71
|
+
</body>
|
72
|
+
</html>
|
73
|
+
```
|
74
|
+
|
75
|
+
```javascript
|
76
|
+
window.addEventListener("DOMContentLoaded", () => {
|
77
|
+
const canvasEle =
|
78
|
+
document.getElementById("Canvas");
|
79
|
+
var ctx;
|
80
|
+
var ext = 1;
|
81
|
+
|
82
|
+
var touches = [];
|
83
|
+
|
84
|
+
var Cwidth = 900,
|
85
|
+
Cheight = 600;
|
86
|
+
|
87
|
+
function game() {
|
88
|
+
ctx.clearRect(0, 0, Cwidth, Cheight);
|
89
|
+
ctx.fillStyle = "#fff";
|
90
|
+
for (t of touches) {
|
91
|
+
const x = getTouchesXY(t)[0];
|
92
|
+
ctx.fillRect(x - 5, 0, 10, 600);
|
93
|
+
}
|
94
|
+
window.requestAnimationFrame(game);
|
95
|
+
}
|
96
|
+
|
97
|
+
function init() {
|
98
|
+
ctx = canvasEle.getContext("2d");
|
99
|
+
setSize();
|
100
|
+
window.requestAnimationFrame(game);
|
101
|
+
}
|
102
|
+
|
103
|
+
canvasEle.addEventListener("touchstart", () => {
|
104
|
+
event.preventDefault();
|
105
|
+
touches = event.touches;
|
106
|
+
}, {
|
107
|
+
passive: false
|
108
|
+
});
|
109
|
+
|
110
|
+
canvasEle.addEventListener("touchmove", () => {
|
111
|
+
event.preventDefault();
|
112
|
+
touches = event.touches;
|
113
|
+
}, {
|
114
|
+
passive: false
|
115
|
+
});
|
116
|
+
|
117
|
+
canvasEle.addEventListener("touchend", () => {
|
118
|
+
event.preventDefault();
|
119
|
+
touches = event.touches;
|
120
|
+
}, {
|
121
|
+
passive: false
|
122
|
+
});
|
123
|
+
|
124
|
+
canvasEle.addEventListener("touchcancel", () => {
|
125
|
+
event.preventDefault();
|
126
|
+
touches = event.touches;
|
127
|
+
}, {
|
128
|
+
passive: false
|
129
|
+
});
|
130
|
+
|
131
|
+
function setSize() {
|
132
|
+
var height = window.innerHeight;
|
133
|
+
var width = window.innerWidth;
|
134
|
+
|
135
|
+
Cheight = 600;
|
136
|
+
Cwidth = Math.floor(600 * width / height);
|
137
|
+
canvasEle.width = Cwidth;
|
138
|
+
canvasEle.height = Cheight;
|
139
|
+
|
140
|
+
ext = height / 600;
|
141
|
+
|
142
|
+
canvasEle.style.width = (Cwidth * ext) + "px";
|
143
|
+
canvasEle.style.height = (Cheight * ext) + "px";
|
144
|
+
|
145
|
+
var wrap = document.getElementById('wrapper');
|
146
|
+
wrap.style.width = canvasEle.style.width;
|
147
|
+
wrap.style.height = canvasEle.style.height;
|
148
|
+
}
|
149
|
+
|
150
|
+
function getTouchesXY(touch) {
|
151
|
+
var rect = canvasEle.getBoundingClientRect();
|
152
|
+
let x = (touch.clientX - (rect.left + window.pageXOffset)) / ext;
|
153
|
+
let y = (touch.clientY - (rect.top + window.pageYOffset)) / ext;
|
154
|
+
return [x, y];
|
155
|
+
}
|
156
|
+
|
157
|
+
window.addEventListener("resize", setSize);
|
158
|
+
window.addEventListener("orientationchange", setSize);
|
159
|
+
init();
|
160
|
+
});
|
161
|
+
|
162
|
+
```
|