Skip to content

Commit 5e3c3af

Browse files
author
Carlos Filoteo
committed
Add solution for project 02.
1 parent 6842573 commit 5e3c3af

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,35 @@
6161
background:black;
6262
position: absolute;
6363
top:50%;
64+
transform-origin: 100%;
65+
transform: rotate(90deg);
66+
transition: all 0.05s;
67+
transition-timing-function: cubic-bezier(0.42, 0, 0.25, 1.85);
6468
}
6569

6670
</style>
6771

68-
<script>
72+
<script>
73+
const secondHand = document.querySelector('.second-hand'),
74+
minuteHand = document.querySelector('.min-hand'),
75+
hourHand = document.querySelector('.hour-hand')
6976

77+
function setTime() {
78+
const now = new Date(),
79+
seconds = getRotation(now.getSeconds(), 60),
80+
minutes = getRotation(now.getMinutes(), 60),
81+
hours = getRotation(now.getHours(), 12)
82+
83+
secondHand.style.transform = `rotate(${ seconds }deg)`
84+
minuteHand.style.transform = `rotate(${ minutes }deg)`
85+
hourHand.style.transform = `rotate(${ hours }deg)`
86+
}
7087

71-
</script>
88+
function getRotation(timeValue, scale) {
89+
return (timeValue / scale * 360) + 90
90+
}
91+
92+
setInterval(setTime, 1000)
93+
</script>
7294
</body>
7395
</html>

0 commit comments

Comments
 (0)