-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
129 lines (110 loc) · 3.24 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
<!DOCTYPE HTML>
<html>
<style>
body {
background: black;
color: white;
}
body a {
text-decoration: none;
color: white;
}
</style>
<script>
const colors = [
"#fe0000",
"#fdfe02",
"#0bff01",
"#011efe",
"#fe00f6"
];
const getRandom = () => Math.floor(Math.random() * 201) - 100;
const parseTopLeftNum = str => parseInt(str.slice(0, str.length - 2), 10);
window.onload = () => {
const nodes = [
{ top: 0, left: 0 },
{ top: 20, left: 0 },
{ top: 40, left: 0 },
{ top: 60, left: 0 },
{ top: 80, left: 0 },
{ top: 80, left: 20 },
{ top: 80, left: 40 },
{ top: 0, left: 80 },
{ top: 20, left: 80 },
{ top: 40, left: 80 },
{ top: 60, left: 80 },
{ top: 80, left: 80 },
{ top: 80, left: 100 },
{ top: 80, left: 120 },
{ top: 0, left: 120 },
{ top: 20, left: 120 },
{ top: 40, left: 120 },
{ top: 60, left: 120 },
{ top: 0, left: 160 },
{ top: 20, left: 160 },
{ top: 40, left: 160 },
{ top: 60, left: 160 },
{ top: 80, left: 160 },
{ top: 40, left: 180 },
{ top: 20, left: 200 },
{ top: 60, left: 200 },
{ top: 0, left: 220 },
{ top: 80, left: 220 },
{ top: 0, left: 260 },
{ top: 0, left: 280 },
{ top: 0, left: 300 },
{ top: 20, left: 260 },
{ top: 40, left: 280 },
{ top: 40, left: 300 },
{ top: 40, left: 260 },
{ top: 60, left: 260 },
{ top: 80, left: 260 },
{ top: 80, left: 280 },
{ top: 80, left: 300 },
];
const container = document.getElementById("funstuff");
const timeouts = {};
for (const node of nodes) {
const div = document.createElement("div");
const originalLeft = `${node.left + 90}px`;
const originalTop = `${node.top + 90}px`;
div.style.height = "20px";
div.style.width = "20px";
div.style.position = "absolute";
div.style.top = originalTop;
div.style.left = originalLeft;
div.style.background = colors[Math.floor(Math.random() * colors.length)];
div.style.transition = "all 0.5s ease-in";
div.setAttribute("data-original-location", `${originalTop}-${originalLeft}`);
container.append(div);
}
container.addEventListener("mouseover", (e) => {
if (!e.target.getAttribute("data-original-location")) return;
const currentTop = parseTopLeftNum(e.target.style.top);
const currentLeft = parseTopLeftNum(e.target.style.left);
e.target.style.top = currentTop + getRandom() + "px";
e.target.style.left = currentLeft + getRandom() + "px";
if (timeouts[e.target.getAttribute("data-original-location")]) {
clearTimeout(timeouts[e.target.getAttribute("data-original-location")]);
}
const timeout = setTimeout(() => {
const original = e.target.getAttribute("data-original-location").split("-");
e.target.style.top = original[0];
e.target.style.left = original[1];
}, 3000);
timeouts[e.target.getAttribute("data-original-location")] = timeout;
});
}
</script>
<head>
<title></title>
</head>
<body>
<a href="mailto:[email protected]">[email protected]</a>
<div
id="funstuff"
style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); height: 300px; width: 500px;"
>
</div>
</body>
</html>