-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
102 lines (75 loc) · 2.77 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Reaction Test</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<style>
@import url('https://fonts.googleapis.com/css?family=Slabo+27px');
#shape {
height: 200px;
width: 200px;
background: red;
display: none;
position: relative;
transform: rotate(45deg);
border: 2px solid #000;
}
body {
text-align: center;
font-family: "Slabo 27px";
background: linear-gradient(to right, #C9EFD9, #FFF6DD);
font-size: 20px;
}
.bold {
font-weight: bold;
}
</style>
</head>
<body>
<h1>Test your reaction!</h1>
<p>Click on the diamonds and circles as quickly as you can~</p>
<p class="bold">Your time: <span id="time"></span></p>
<div id="shape"></div>
</body>
<script type="text/javascript">
var start = new Date().getTime();
var item = document.getElementById("shape");
function randomColor () {
var letters="0123456789ABCDEF".split("");
var color = "#";
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
function newShape() {
var top = Math.random() * 400;
var left = Math.random() * 500;
var width = (Math.random() * 200) + 100;
if (Math.random() > 0.5) {
item.style.borderRadius = "50%";
} else {
item.style.borderRadius = "0%";
}
item.style.backgroundColor = randomColor();
item.style.left = left + "px";
item.style.top = top + "px";
item.style.width = width + "px";
item.style.height = width + "px";
item.style.display = "block";
start = new Date().getTime();
}
function appearDelay() {
setTimeout(newShape, Math.random() * 2000);
}
appearDelay();
item.onclick = function () {
item.style.display = "none";
var end = new Date().getTime();
var time = (end - start)/1000;
document.getElementById("time").innerHTML = time + "s";
appearDelay();
}
</script>
</html>