-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
26 lines (24 loc) · 960 Bytes
/
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
const hrsTens = document.getElementById("hrsTens");
const hrsOnes = document.getElementById("hrsOnes");
const minTens = document.getElementById("minTens");
const minOnes = document.getElementById("minOnes");
const secTens = document.getElementById("secTens");
const secOnes = document.getElementById("secOnes");
function setTime(time, tens, ones) {
if (time >= 10) {
time = time.toString().split("");
tens.style.transform = `translateY(-${Number(time[0]) * 100}%)`;
ones.style.transform = `translateY(-${Number(time[1]) * 100}%)`;
} else {
time = time.toString().split("");
time.unshift("0");
tens.style.transform = `translateY(-${Number(time[0]) * 100}%)`;
ones.style.transform = `translateY(-${Number(time[1]) * 100}%)`;
}
}
setInterval(() => {
let time = new Date();
setTime(time.getSeconds(), secTens, secOnes);
setTime(time.getMinutes(), minTens, minOnes);
setTime(time.getHours(), hrsTens, hrsOnes);
}, 1000);