-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
52 lines (40 loc) · 1.32 KB
/
script.js
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
const strips = [...document.querySelectorAll(".strip")];
const numberSize = "4"; // in rem
var lastTime = new Array(-1, -1, -1)
// highlight number i on strip s for 1 second
function highlight(strip, d) {
strips[strip]
.querySelector(`.number:nth-of-type(${d + 1})`)
.classList.add("pop");
setTimeout(() => {
strips[strip]
.querySelector(`.number:nth-of-type(${d + 1})`)
.classList.remove("pop");
}, 950); // causes ticking
}
function stripSlider(strip, id, number) {
let d1 = Math.floor(number / 10);
let d2 = number % 10;
if (lastTime[id] == -1 || lastTime[id] != number) {
strips[strip].style.transform = `translateY(${d1 * -numberSize}rem)`;
strips[strip + 1].style.transform = `translateY(${d2 * -numberSize}rem)`;
lastTime[id] = number;
}
highlight(strip, d1);
highlight(strip + 1, d2);
}
function updateClock() {
// get new time
const time = new Date();
// get h,m,s
const hours = time.getHours();
const mins = time.getMinutes();
const secs = time.getSeconds();
// slide strips
stripSlider(0, 0, hours);
stripSlider(2, 1, mins);
stripSlider(4, 2, secs);
}
// set Timer for clock-update
setInterval(updateClock, 1000);
updateClock();