Skip to content

Commit e1b5663

Browse files
committed
day 2 - JS Clock done!
1 parent a99dea5 commit e1b5663

File tree

1 file changed

+52
-25
lines changed

1 file changed

+52
-25
lines changed

02 - JS + CSS Clock/index-START.html

+52-25
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<meta charset="UTF-8">
5-
<title>JS + CSS Clock</title>
4+
<meta charset="UTF-8">
5+
<title>JS + CSS Clock</title>
66
</head>
77
<body>
88

99

10-
<div class="clock">
10+
<div class="clock">
1111
<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>
12+
<div class="hand hour-hand"></div>
13+
<div class="hand min-hand"></div>
14+
<div class="hand second-hand"></div>
1515
</div>
16-
</div>
16+
</div>
1717

1818

19-
<style>
20-
html {
19+
<style>
20+
html {
2121
background:#018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
2222
background-size:cover;
2323
font-family:'helvetica neue';
2424
text-align: center;
2525
font-size: 10px;
26-
}
26+
}
2727

28-
body {
28+
body {
2929
font-size: 2rem;
3030
display:flex;
3131
flex:1;
3232
min-height: 100vh;
3333
align-items: center;
34-
}
34+
}
3535

36-
.clock {
36+
.clock {
3737
width: 30rem;
3838
height: 30rem;
3939
border:20px solid white;
@@ -42,32 +42,59 @@
4242
position: relative;
4343
padding:2rem;
4444
box-shadow:
45-
0 0 0 4px rgba(0,0,0,0.1),
46-
inset 0 0 0 3px #EFEFEF,
47-
inset 0 0 10px black,
48-
0 0 10px rgba(0,0,0,0.2);
49-
}
45+
0 0 0 4px rgba(0,0,0,0.1),
46+
inset 0 0 0 3px #EFEFEF,
47+
inset 0 0 10px black,
48+
0 0 10px rgba(0,0,0,0.2);
49+
}
5050

51-
.clock-face {
51+
.clock-face {
5252
position: relative;
5353
width: 100%;
5454
height: 100%;
5555
transform: translateY(-3px); /* account for the height of the clock hands */
56-
}
56+
}
5757

58-
.hand {
58+
.hand {
5959
width:50%;
6060
height:6px;
6161
background:black;
6262
position: absolute;
6363
top:50%;
64-
}
64+
border-radius: 10px 0 0 10px;
6565

66-
</style>
66+
transform: rotate(90deg);
67+
transform-origin: right;
68+
transition: all 0.5s;
69+
transition-timing-function: cubic-bezier(0.01, 1.14, 1, 1.08);
70+
}
6771

68-
<script>
72+
.hour-hand {
73+
width: 30%;
74+
left: 20%;
75+
}
6976

77+
</style>
7078

71-
</script>
79+
<script type="text/javascript">
80+
81+
const secondHand = document.querySelector('.second-hand');
82+
const minHand = document.querySelector('.min-hand');
83+
const hourHand = document.querySelector('.hour-hand');
84+
function setDate() {
85+
const time = new Date();
86+
const secondDegrees = time.getSeconds() /60 * 360 + 90;
87+
const minDegrees = time.getMinutes() / 60 * 360 + 90;
88+
const hourDegrees = time.getHours() / 12 * 360 + 90;
89+
90+
secondHand.style.transform = `rotate(${secondDegrees}deg)`;
91+
minHand.style.transform = `rotate(${minDegrees}deg)`;
92+
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
93+
94+
}
95+
96+
setInterval(setDate, 1000);
97+
98+
</script>
7299
</body>
73100
</html>

0 commit comments

Comments
 (0)