Skip to content

Commit fcb0ec5

Browse files
committed
JS30 wesbos#2 complete
1 parent fcb013d commit fcb0ec5

File tree

1 file changed

+80
-60
lines changed

1 file changed

+80
-60
lines changed
Lines changed: 80 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,94 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8">
5-
<title>JS + CSS Clock</title>
6-
</head>
7-
<body>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>JS + CSS Clock</title>
6+
</head>
7+
<body>
8+
<div class="clock">
9+
<div class="clock-face">
10+
<div class="hand hour-hand"></div>
11+
<div class="hand min-hand"></div>
12+
<div class="hand second-hand"></div>
13+
</div>
14+
</div>
815

16+
<style>
17+
html {
18+
background: #018ded
19+
url(https://unsplash.it/1500/1000?image=881&blur=5);
20+
background-size: cover;
21+
font-family: "helvetica neue";
22+
text-align: center;
23+
font-size: 10px;
24+
}
925

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>
16-
</div>
26+
body {
27+
margin: 0;
28+
font-size: 2rem;
29+
display: flex;
30+
flex: 1;
31+
min-height: 100vh;
32+
align-items: center;
33+
}
1734

35+
.clock {
36+
width: 30rem;
37+
height: 30rem;
38+
border: 20px solid white;
39+
border-radius: 50%;
40+
margin: 50px auto;
41+
position: relative;
42+
padding: 2rem;
43+
box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.1),
44+
inset 0 0 0 3px #efefef, inset 0 0 10px black,
45+
0 0 10px rgba(0, 0, 0, 0.2);
46+
}
1847

19-
<style>
20-
html {
21-
background: #018DED url(https://unsplash.it/1500/1000?image=881&blur=5);
22-
background-size: cover;
23-
font-family: 'helvetica neue';
24-
text-align: center;
25-
font-size: 10px;
26-
}
48+
.clock-face {
49+
position: relative;
50+
width: 100%;
51+
height: 100%;
52+
transform: translateY(
53+
-3px
54+
); /* account for the height of the clock hands */
55+
}
2756

28-
body {
29-
margin: 0;
30-
font-size: 2rem;
31-
display: flex;
32-
flex: 1;
33-
min-height: 100vh;
34-
align-items: center;
35-
}
57+
.hand {
58+
width: 50%;
59+
height: 6px;
60+
background: black;
61+
position: absolute;
62+
top: 50%;
63+
transform-origin: 100%;
64+
transform: rotate(90deg);
65+
transition: all 0.05s;
66+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
67+
}
68+
</style>
3669

37-
.clock {
38-
width: 30rem;
39-
height: 30rem;
40-
border: 20px solid white;
41-
border-radius: 50%;
42-
margin: 50px auto;
43-
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);
50-
}
70+
<script>
71+
const secondHand = document.querySelector(".second-hand");
72+
const minuteHand = document.querySelector(".min-hand");
73+
const hourHand = document.querySelector(".hour-hand");
5174

52-
.clock-face {
53-
position: relative;
54-
width: 100%;
55-
height: 100%;
56-
transform: translateY(-3px); /* account for the height of the clock hands */
57-
}
75+
function setDate() {
76+
const now = new Date();
5877

59-
.hand {
60-
width: 50%;
61-
height: 6px;
62-
background: black;
63-
position: absolute;
64-
top: 50%;
65-
}
78+
const seconds = now.getSeconds();
79+
const secondsDegrees = (seconds / 60) * 360 + 90;
80+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
6681

67-
</style>
82+
const minutes = now.getMinutes();
83+
const minutesDegrees = (minutes / 60) * 360 + 90;
84+
minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
6885

69-
<script>
86+
const hours = now.getHours();
87+
const hoursDegrees = (hours / 12) * 360 + 90;
88+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
89+
}
7090

71-
72-
</script>
73-
</body>
91+
setInterval(setDate, 1000);
92+
</script>
93+
</body>
7494
</html>

0 commit comments

Comments
 (0)