Skip to content

Commit 2656ddd

Browse files
did everything in the episode
1 parent 337d680 commit 2656ddd

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<div class="clock-face">
1212
<div class="hand hour-hand"></div>
1313
<div class="hand min-hand"></div>
14-
<div class="hand second-hand"></div>
14+
<div class="hand second-hand" style="transform: rotate(-90);"></div>
1515
</div>
1616
</div>
1717

@@ -53,6 +53,8 @@
5353
width: 100%;
5454
height: 100%;
5555
transform: translateY(-3px); /* account for the height of the clock hands */
56+
transition: all 0.05s;
57+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
5658
}
5759

5860
.hand {
@@ -61,12 +63,33 @@
6163
background:black;
6264
position: absolute;
6365
top:50%;
66+
transform-origin: 100;
67+
transform: rotate(90deg);
6468
}
6569

6670
</style>
6771

6872
<script>
73+
const secondHand = document.querySelector('.second-hand');
74+
const minsHand = document.querySelector('.min-hand');
75+
const hoursHand = document.querySelector('.hour-hand');
6976

77+
function setDate() {
78+
const now = new Date();
79+
const seconds = now.getSeconds();
80+
const secondsDegrees = ((seconds / 60) * 360) + 90;
81+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
82+
83+
const mins = now.getMinutes();
84+
const minDegrees = ((mins /60) * 360) + 90;
85+
minsHand.style.transform = `rotate(${minDegrees}deg)`;
86+
87+
const hour = now.getHours();
88+
const hourDegrees = ((hour / 12) * 360) + 90;
89+
hoursHand.style.transform = `rotate(${hourDegrees}deg)`;
90+
}
91+
92+
setInterval(setDate, 1000);
7093

7194
</script>
7295
</body>

0 commit comments

Comments
 (0)