Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 024918f

Browse files
author
Patrick Santos
committed
complete wesbos#2 challenge
1 parent 2026287 commit 024918f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,44 @@
6262
background:black;
6363
position: absolute;
6464
top:50%;
65+
transform-origin: 100%;
66+
transform: rotate(90deg);
6567
}
6668

6769
</style>
6870

6971
<script>
72+
const secondHand = document.querySelector('.second-hand');
73+
const minHand = document.querySelector('.min-hand');
74+
const hourHand = document.querySelector('.hour-hand');
75+
const hands = document.querySelectorAll('.hand');
7076

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)`
7182

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+
const hoursDegrees = ((hours / 12) * 360) + 90;
89+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
90+
91+
if (seconds === 0) {
92+
[...hands].forEach(function (hand) {
93+
hand.style.transition = 'none';
94+
})
95+
} else {
96+
[...hands].forEach(function (hand) {
97+
hand.style.transition = 'all .25s';
98+
})
99+
}
100+
}
101+
102+
setInterval(setDate, 1000)
72103
</script>
73104
</body>
74105
</html>

0 commit comments

Comments
 (0)