Skip to content

Commit 8c8badd

Browse files
MahdiMahdi
Mahdi
authored and
Mahdi
committed
Fun with css transforms
1 parent 11502ec commit 8c8badd

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,34 @@
6161
background:black;
6262
position: absolute;
6363
top:50%;
64+
transform: rotate(90deg);
65+
transform-origin: 100%;
66+
transition: all 0.05s;
67+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
6468
}
6569

6670
</style>
6771

6872
<script>
6973

74+
const secondHand = document. querySelector(".second-hand");
75+
const minuteHand = document. querySelector(".min-hand");
76+
const hourHand = document. querySelector(".hour-hand");
77+
78+
function setDate() {
79+
const now = new Date();
80+
const seconds = now.getSeconds();
81+
const secondsDegrees = ((seconds / 60) * 360) + 90;
82+
const minutes = now.getMinutes();
83+
const minutesDegrees = ((minutes / 60) * 360) + 90;
84+
const hours = now.getHours();
85+
const hoursDegrees = ((hours / 12) * 360) + 90;
86+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
87+
minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
88+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
89+
}
90+
91+
setInterval(setDate, 1000);
7092

7193
</script>
7294
</body>

0 commit comments

Comments
 (0)