-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
30 lines (26 loc) · 1.18 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const secondHand = document.querySelector('.second-hand');
const minuteHand = document.querySelector('.min-hand');
const hourHand = document.querySelector('.hour-hand');
function setDate() {
const now = new Date();
const seconds = now.getSeconds();
const minutes = now.getMinutes();
const hours = now.getHours();
const secondsDegrees = ((seconds / 60) * 360) + 90;
const minutesDegrees = ((minutes / 60) * 360) + 90;
const hoursDegrees = ((hours / 60) * 360) + 90;
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
// the below if statement is to turn off the transition for when it reaches the top and rewinds back funny
if(seconds === 0) {
secondHand.style.transitionDuration = '0s';
minuteHand.style.transitionDuration = '0s';
hourHand.style.transitionDuration = '0s';
} else {
secondHand.style.transitionDuration = '0.2s';
minuteHand.style.transitionDuration = '0.2s';
hourHand.style.transitionDuration = '0.2s';
}
}
setInterval(setDate, 1000);