-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock.html
executable file
·118 lines (103 loc) · 2.7 KB
/
clock.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
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div id="clockiclock"></div>
<div id="status"></div>
</body>
<style>
body {
background-color: #121212;
}
#clockiclock {
position: absolute;
top: 0px;
left: 300px;
background-color: #00a274;
color: aliceblue;
width: 50%;
padding: 1rem;
border-radius: 0.5rem;
text-align: center;
font-size: 6rem;
font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande",
"Lucida Sans", Arial, sans-serif;
}
#status {
display: none;
position: absolute;
right: 0;
bottom: 0;
color: aliceblue;
}
</style>
<script>
let id = window.setTimeout(function () {}, 0);
while (id--) {
window.clearTimeout(id); // will do nothing if no timeout with id is present
}
const el = document.getElementById("clockiclock");
const statWindow = document.querySelector("#status");
let signLR = 1;
let signUD = 1;
function moveClock() {
let [h, w] = [window.innerHeight, window.innerWidth];
const rect = el.getBoundingClientRect();
let [x, y, wh, ww] = [rect.left, rect.top, rect.height, rect.width].map(
Math.round
);
statWindow.innerText = el.style.top + "\n" + rect.top + "\n";
y = Number(String(el.style.top).slice(0, -2));
// console.log(y)
if (x + ww + signLR >= w) {
el.style.left = w - ww - 1 + "px";
signLR = -1;
} else {
if (x + signLR < 0) {
el.style.left = 0;
signLR = 1;
} else {
el.style.left = x + signLR + "px";
}
}
statWindow.innerText += " - y" + y;
if (y + wh + signUD >= h) {
el.style.top = h - wh - 1 + "px";
signUD = -1;
statWindow.innerText += " ^ ";
} else {
if (y + signUD < 0) {
el.style.top = 0;
signUD = 1;
statWindow.innerText += " v ";
} else {
el.style.top = y + signUD + "px";
statWindow.innerText += " - y" + y;
}
}
statWindow.innerText +=
"ud" +
signUD +
" | y" +
y +
" | wh" +
wh +
" | h" +
h +
" |top" +
el.style.top +
"\n";
}
setInterval(moveClock, 50);
function update() {
const d = new Date();
el.innerText = d.toLocaleTimeString();
setTimeout(update, (Math.PI / 2) * 1000);
}
setTimeout(update, 0);
</script>
</html>