Skip to content

Commit 9c88f74

Browse files
PierreM-Devroot
authored and
root
committed
Finish exercice 2
1 parent 30c12db commit 9c88f74

File tree

1 file changed

+74
-54
lines changed

1 file changed

+74
-54
lines changed
Lines changed: 74 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,94 @@
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>
6+
7+
<style>
8+
html {
9+
background: #018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
10+
background-size: cover;
11+
font-family: 'helvetica neue', serif;
12+
text-align: center;
13+
font-size: 10px;
14+
}
15+
16+
body {
17+
margin: 0;
18+
font-size: 2rem;
19+
display: flex;
20+
flex: 1;
21+
min-height: 100vh;
22+
align-items: center;
23+
}
24+
25+
.clock {
26+
width: 30rem;
27+
height: 30rem;
28+
border: 20px solid white;
29+
border-radius: 50%;
30+
margin: 50px auto;
31+
position: relative;
32+
padding: 2rem;
33+
box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.1),
34+
inset 0 0 0 3px #EFEFEF,
35+
inset 0 0 10px black,
36+
0 0 10px rgba(0, 0, 0, 0.2);
37+
}
38+
39+
.clock-face {
40+
position: relative;
41+
width: 100%;
42+
height: 100%;
43+
transform: translateY(-3px); /* account for the height of the clock hands */
44+
}
45+
46+
.hand {
47+
width: 50%;
48+
height: 6px;
49+
background: black;
50+
position: absolute;
51+
top: 50%;
52+
transform-origin: 100%;
53+
transform: rotate(90deg);
54+
transition: all 0.05s;
55+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
56+
}
57+
</style>
658
</head>
759
<body>
860

9-
10-
<div class="clock">
11-
<div class="clock-face">
61+
<div class="clock">
62+
<div class="clock-face">
1263
<div class="hand hour-hand"></div>
1364
<div class="hand min-hand"></div>
1465
<div class="hand second-hand"></div>
15-
</div>
1666
</div>
67+
</div>
1768

69+
<script>
70+
const secondHand = document.querySelector('.second-hand');
71+
const minsHand = document.querySelector('.min-hand');
72+
const hourHand = document.querySelector('.hour-hand');
1873

19-
<style>
20-
html {
21-
background:#018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
22-
background-size:cover;
23-
font-family:'helvetica neue';
24-
text-align: center;
25-
font-size: 10px;
26-
}
74+
function setDate() {
75+
const now = new Date();
76+
const seconds = now.getSeconds();
77+
const secondsDegrees = ((seconds / 60) * 360) + 90;
2778

28-
body {
29-
margin: 0;
30-
font-size: 2rem;
31-
display:flex;
32-
flex:1;
33-
min-height: 100vh;
34-
align-items: center;
35-
}
36-
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-
}
79+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
5180

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-
}
81+
const mins = now.getMinutes();
82+
const minsDegrees = ((mins / 60) * 360) + 90;
83+
minsHand.style.transform = `rotate(${minsDegrees}deg`;
5884

59-
.hand {
60-
width:50%;
61-
height:6px;
62-
background:black;
63-
position: absolute;
64-
top:50%;
85+
const hours = now.getHours();
86+
const hoursDegrees = ((hours / 12) * 360) + 90;
87+
hourHand.style.transform = `rotate(${hoursDegrees}deg`;
6588
}
6689

67-
</style>
68-
69-
<script>
70-
90+
setInterval(setDate, 1000);
91+
</script>
7192

72-
</script>
7393
</body>
7494
</html>

0 commit comments

Comments
 (0)