Skip to content

Commit a7a42cb

Browse files
committed
02 - JS and CSS Clock
1 parent f730b29 commit a7a42cb

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,51 @@
6262
background: black;
6363
position: absolute;
6464
top: 50%;
65+
transform-origin: 100%;
66+
transform: rotate(90deg);
67+
transition: all 0.5s;
68+
transition-timing-function: cubic-bezier(0.1, 2, 0.5, 1);
69+
}
70+
71+
.second-hand {
72+
height: 3px;
6573
}
6674

6775
</style>
6876

6977
<script>
7078

79+
const secondHand = document.querySelector('.second-hand');
80+
const minutesHand = document.querySelector('.min-hand');
81+
const hoursHand = document.querySelector('.hour-hand');
82+
83+
const hands = document.querySelectorAll('.hand');
84+
85+
function setDate() {
86+
const now = new Date();
87+
const seconds = now.getSeconds();
88+
const minutes = now.getMinutes();
89+
const hours = now.getHours();
90+
console.log(`${hours}:${minutes}:${seconds}`);
91+
92+
const secondsDegrees = (seconds / 60 * 360) + 90;
93+
const minutesDegrees = (minutes / 60 * 365) + 90;
94+
const hoursDegrees = (hours / 12 * 365) + 90;
95+
96+
// Pause transition animation when second hand goes from 59 seconds to 0
97+
if (secondHand.style.transform == 'rotate(444deg)'){
98+
secondHand.style.transition = 'none';
99+
} else if (secondHand.style.transform == 'rotate(90deg)') {
100+
secondHand.style.transition = 'all 0.5s';
101+
}
102+
103+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
104+
minutesHand.style.transform = `rotate(${minutesDegrees}deg)`;
105+
hoursHand.style.transform = `rotate(${hoursDegrees}deg)`;
106+
107+
}
71108

109+
setInterval(setDate, 1000);
72110
</script>
73111
</body>
74112
</html>

0 commit comments

Comments
 (0)