-
Notifications
You must be signed in to change notification settings - Fork 0
/
analog-clock.js
87 lines (74 loc) · 1.98 KB
/
analog-clock.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
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
let hr = document.getElementById('hour');
let min = document.getElementById('min');
let sec = document.getElementById('sec');
function displayTime(){
let date = new Date();
// Getting hour, mins, secs from date
let hh = date.getHours();
let mm = date.getMinutes();
let ss = date.getSeconds();
let hRotation = 30*hh + mm/2;
let mRotation = 6*mm;
let sRotation = 6*ss;
hr.style.transform = `rotate(${hRotation}deg)`;
min.style.transform = `rotate(${mRotation}deg)`;
sec.style.transform = `rotate(${sRotation}deg)`;
}
setInterval(displayTime, 1000);
---
<style>
.clock{
width: 1.25rem;
height: 1.25rem;
border-radius: 50%;
background-color: var(--background-color--background-primary);
border: 2px solid var(--border-color--border-primary);
display: flex;
justify-content: center;
align-items: center;
}
.clock span{
position: absolute;
transform: rotate(calc(30deg * var(--i)));
inset: 12px;
text-align: center;
}
.clock span b{
transform: rotate(calc(-30deg * var(--i)));
display: inline-block;
font-size: 20px;
}
.clock::before{
content: '';
position: absolute;
width: 4px;
height: 4px;
border-radius: 50%;
background-color: var(--background-color--background-alternate);
z-index: 2;
}
.hand{
position: absolute;
display: flex;
justify-content: center;
align-items: flex-end;
}
.hand i{
position: absolute;
background-color: var(--background-color--background-alternate);
width: 1.5px;
height: var(--h);
border-radius: 8px;
}
</style>
<div class="clock">
<div style="--clr: var(--background-color--background-primary); --h: 0.35rem" id="hour" class="hand">
<i></i>
</div>
<div style="--clr: var(--background-color--background-primary); --h: 0.55rem" id="min" class="hand">
<i></i>
</div>
<div style="--clr: var(--background-color--background-primary); --h: 0.6rem" id="sec" class="hand">
<i></i>
</div>
</div>