Skip to content

Commit 799f0d6

Browse files
committed
clock by phil
1 parent dc0ecb1 commit 799f0d6

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

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

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
<div class="clock">
1111
<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>
12+
<div class="hand hour-hand">hour</div>
13+
<div class="hand min-hand">min</div>
14+
<div class="hand second-hand">sec</div>
1515
</div>
1616
</div>
1717

@@ -54,20 +54,48 @@
5454
height: 100%;
5555
transform: translateY(-3px); /* account for the height of the clock hands */
5656
}
57-
5857
.hand {
5958
width:50%;
6059
height:6px;
61-
background:black;
6260
position: absolute;
61+
background: black;
6362
top:50%;
63+
transform-origin: 100%;
64+
transform: rotate(90deg);
65+
transition: ;
66+
transition-timing-function: cubic-bezier(.1, 2.7, .58, 1);
6467
}
65-
6668
</style>
6769

6870
<script>
71+
const secondHand = document.querySelector('.second-hand')
72+
const minuteHand = document.querySelector('.min-hand')
73+
const hourHand = document.querySelector('.hour-hand');
74+
const hand = document.querySelector('.hand');
75+
76+
function setDate() {
77+
const now = new Date();
6978

79+
const seconds = now.getSeconds();
80+
const secondsDegrees = convert(seconds);
81+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
82+
83+
const minutes = now.getMinutes();
84+
const minutesDegrees = convert(minutes);
85+
minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
86+
87+
const hours = now.getHours();
88+
const hoursDegrees = convert(hours);
89+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
90+
if (seconds === 0 || minutes === 0 || hours === 0) {
91+
hand.style.transition = 'none';
92+
}
93+
}
7094

95+
function convert (numb) {
96+
return (((numb / 60) * 360) + 90);
97+
}
98+
setInterval(setDate, 1000);
7199
</script>
72100
</body>
73101
</html>

0 commit comments

Comments
 (0)