-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
153 lines (97 loc) · 3.11 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html lang="zh-Hant-TW">
<head>
<title>考反應遊戲</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
/*變量 */
/* :root {
--bound: 80px;
} */
body {
background-color: rgba(255, 94, 100, 0.5);
color : #FF3864;
}
.bold {
font-weight: bold;
}
#box {
width: 140px;
/* width: var(--bound); */
height: 140px;
/* height: var(--bound); */
background-color: red;
display: none;
position: relative;
}
</style>
</head>
<body>
<h1>考考你的反應!</h1>
<p class="bold">反應時間 : <span id="time">0</span>秒</p>
<div id="box"></div>
<script type="text/javascript">
var creatdTime;
var clickedTime;
var reactionTime;
function getRandomColor() {
var max = 200;
var min = 50;
var green = Math.floor(Math.random() * (max - min + 1)) + min;
var color = "rgba(255, " + green + ", 100, 1.0)";
return color;
}
function makeBox() {
var time = Math.random();
time = time * 2000;
setTimeout(function() {
if (Math.random() >= 0.5) {
document.getElementById('box').style.borderRadius = "70px";
} else {
document.getElementById('box').style.borderRadius = "0px";
} //隨機圖形
// console.log(window.innerWidth);
// console.log(window.innerHeight);
//
// console.log(document.documentElement.clientWidth);
// console.log(document.documentElement.clientHeight);
var min = 0;
var max = window.innerHeight - 280 ; //扣除圖形以及文字高度
var top = Math.floor(Math.random() * (max - min +1)) +min;
min = 0;
max = window.innerWidth - 140;
// var dynamicBound;
// if (window.innerWidth > window.innerHeight) {
//
// dynamicBound = window.innerWidth / 8 ;
// console.log("Width:" + dynamicBound);
//
// } else {
//
// dynamicBound = window.innerHeight / 8 ;
// console.log("Height:" + dynamicBound);
//
// }
//
// dynamicBound = dynamicBound + "px" ; //動態變量
// document.documentElement.style.setProperty("--bound", dynamicBound);
var left = Math.floor(Math.random() * (max - min +1)) +min;
document.getElementById('box').style.top = top + "px"; //隨機位置
document.getElementById('box').style.left = left + "px"; //隨機位置
document.getElementById('box').style.backgroundColor = getRandomColor();
document.getElementById('box').style.display = "block";
creatdTime = Date.now();
}, time); // (function , ms)
}
document.getElementById('box').onclick = function() {
this.style.display = "none";
clickedTime = Date.now();
reactionTime = (clickedTime - creatdTime) / 1000; //單位 s
document.getElementById('time').innerHTML = reactionTime;
makeBox();
}
makeBox();
</script>
</body>
</html>