Skip to content

Commit e0ea6d7

Browse files
committed
Finish clock challenge.
1 parent 175b719 commit e0ea6d7

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
</head>
77
<body>
88

9-
109
<div class="clock">
1110
<div class="clock-face">
1211
<div class="hand hour-hand"></div>
@@ -15,8 +14,8 @@
1514
</div>
1615
</div>
1716

18-
1917
<style>
18+
2019
html {
2120
background:#018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
2221
background-size:cover;
@@ -61,13 +60,37 @@
6160
background:black;
6261
position: absolute;
6362
top:50%;
63+
transform-origin: 100%;
64+
transform: rotate(90deg);
65+
transition: all 0.05s;
66+
transition-timing-function: cubic-bezier(0.65, 0.05, 0.36, 1);
6467
}
6568

6669
</style>
6770

6871
<script>
6972

73+
const secondHand = document.querySelector('.second-hand');
74+
const minHand = document.querySelector('.min-hand');
75+
const hourHand = document.querySelector('.hour-hand');
76+
77+
function setDate() {
78+
const now = new Date();
79+
const seconds = now.getSeconds();
80+
const secondsDegrees = ((seconds / 60) * 360) + 90; // Because we offset the starting position of the hands to start at 12:00 we have to offset this by 90 as well
81+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
82+
83+
const mins = now.getMinutes();
84+
const minsDegrees = ((mins / 60) * 360) + 90;
85+
minHand.style.transform = `rotate(${minsDegrees}deg)`;
86+
87+
const hours = now.getHours();
88+
console.log(hours, ':', mins, ':', seconds);
89+
const hoursDegrees = ((hours / 12) * 360) + 90;
90+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
91+
}
7092

93+
setInterval(setDate, 1000);
7194
</script>
7295
</body>
7396
</html>

0 commit comments

Comments
 (0)