Visitar URL original
finishes 02 · wesbos/JavaScript30@4de39fa · GitHub
Skip to content

Commit 4de39fa

Browse files
committed
finishes 02
1 parent efcdf2f commit 4de39fa

1 file changed

Lines changed: 67 additions & 45 deletions

File tree

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

Lines changed: 67 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,57 +16,79 @@
1616
</div>
1717

1818

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-
}
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+
}
2727

28-
body {
29-
font-size: 2rem;
30-
display:flex;
31-
flex:1;
32-
min-height: 100vh;
33-
align-items: center;
34-
}
28+
body {
29+
font-size: 2rem;
30+
display:flex;
31+
flex:1;
32+
min-height: 100vh;
33+
align-items: center;
34+
}
3535

36-
.clock {
37-
width: 30rem;
38-
height: 30rem;
39-
border:20px solid white;
40-
border-radius:50%;
41-
margin:50px auto;
42-
position: relative;
43-
padding:2rem;
44-
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-
}
36+
.clock {
37+
width: 30rem;
38+
height: 30rem;
39+
border:20px solid white;
40+
border-radius:50%;
41+
margin:50px auto;
42+
position: relative;
43+
padding:2rem;
44+
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+
}
5050

51-
.clock-face {
52-
position: relative;
53-
width: 100%;
54-
height: 100%;
55-
transform: translateY(-3px); /* account for the height of the clock hands */
56-
}
57-
58-
.hand {
59-
width:50%;
60-
height:6px;
61-
background:black;
62-
position: absolute;
63-
transform-origin: 100%;
64-
top:50%;
65-
}
51+
.clock-face {
52+
position: relative;
53+
width: 100%;
54+
height: 100%;
55+
transform: translateY(-3px); /* account for the height of the clock hands */
56+
}
6657

58+
.hand {
59+
width:50%;
60+
height:6px;
61+
background:black;
62+
position: absolute;
63+
top:50%;
64+
transform-origin: 100%;
65+
transform: rotate(90deg);
66+
transition: all 0.05s;
67+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
68+
}
6769
</style>
6870
<script>
69-
71+
const secondHand = document.querySelector('.second-hand');
72+
const minuteHand = document.querySelector('.min-hand');
73+
const hourHand = document.querySelector('.hour-hand');
74+
75+
function setDate() {
76+
const now = new Date();
77+
const seconds = now.getSeconds();
78+
const minutes = now.getMinutes();
79+
const hours = now.getHours();
80+
81+
console.log(minutes, hours);
82+
const secondsDegrees = ((seconds / 60) * 360) + 90;
83+
const minutesDegrees = ((minutes / 60) * 360) + 90;
84+
const hoursDegrees = ((hours / 60) * 360) + 90;
85+
86+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
87+
minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
88+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
89+
}
90+
91+
setInterval(setDate, 1000);
7092

7193
</script>
7294
</body>

0 commit comments

Comments
 (0)