Skip to content

Commit 48aebd7

Browse files
committed
implement day 02
1 parent ade80f5 commit 48aebd7

1 file changed

Lines changed: 53 additions & 27 deletions

File tree

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,100 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<title>JS + CSS Clock</title>
67
</head>
8+
79
<body>
810

911

10-
<div class="clock">
11-
<div class="clock-face">
12-
<div class="hand hour-hand"></div>
13-
<div class="hand min-hand"></div>
14-
<div class="hand second-hand"></div>
15-
</div>
12+
<div class="clock">
13+
<div class="clock-face">
14+
<div class="hand hour-hand"></div>
15+
<div class="hand min-hand"></div>
16+
<div class="hand second-hand"></div>
1617
</div>
18+
</div>
1719

1820

1921
<style>
2022
html {
21-
background:#018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
22-
background-size:cover;
23-
font-family:'helvetica neue';
23+
background: #018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
24+
background-size: cover;
25+
font-family: 'helvetica neue';
2426
text-align: center;
2527
font-size: 10px;
2628
}
2729

2830
body {
2931
margin: 0;
3032
font-size: 2rem;
31-
display:flex;
32-
flex:1;
33+
display: flex;
34+
flex: 1;
3335
min-height: 100vh;
3436
align-items: center;
3537
}
3638

3739
.clock {
3840
width: 30rem;
3941
height: 30rem;
40-
border:20px solid white;
41-
border-radius:50%;
42-
margin:50px auto;
42+
border: 20px solid white;
43+
border-radius: 50%;
44+
margin: 50px auto;
4345
position: relative;
44-
padding:2rem;
45-
box-shadow:
46-
0 0 0 4px rgba(0,0,0,0.1),
47-
inset 0 0 0 3px #EFEFEF,
48-
inset 0 0 10px black,
49-
0 0 10px rgba(0,0,0,0.2);
46+
padding: 2rem;
47+
box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.1),
48+
inset 0 0 0 3px #EFEFEF,
49+
inset 0 0 10px black,
50+
0 0 10px rgba(0, 0, 0, 0.2);
5051
}
5152

5253
.clock-face {
5354
position: relative;
5455
width: 100%;
5556
height: 100%;
56-
transform: translateY(-3px); /* account for the height of the clock hands */
57+
transform: translateY(-3px);
58+
/* account for the height of the clock hands */
5759
}
5860

5961
.hand {
60-
width:50%;
61-
height:6px;
62-
background:black;
62+
width: 50%;
63+
height: 6px;
64+
background: black;
6365
position: absolute;
64-
top:50%;
66+
top: 50%;
67+
transform-origin: 100%;
68+
transform: rotate(90deg);
69+
transition: all 0.05s;
70+
transition-timing-function: cubic-bezier(0, 2.22, .58, 1);
6571
}
66-
6772
</style>
6873

6974
<script>
75+
const secondHand = document.querySelector('.second-hand');
76+
const minutesHand = document.querySelector('.min-hand');
77+
const hoursHand = document.querySelector('.hour-hand');
78+
79+
function setDate() {
80+
const now = new Date();
81+
const seconds = now.getSeconds();
82+
const secondsDegrees = ((seconds / 60) * 360) + 90;
83+
84+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
7085

86+
const minutes = now.getMinutes();
87+
const minutesDegrees = ((minutes / 60) * 360) + 90;
88+
minutesHand.style.transform = `rotate(${minutesDegrees}deg)`
7189

90+
const hours = now.getHours();
91+
const hoursDegrees = ((hours / 12) * 360) + 90;
92+
hoursHand.style.transform = `rotate(${hoursDegrees}deg)`
93+
94+
}
95+
96+
setInterval(setDate, 1000);
7297
</script>
7398
</body>
74-
</html>
99+
100+
</html>

0 commit comments

Comments
 (0)