Skip to content

Commit 92c9f46

Browse files
committed
Finish day 2️⃣ exercise
Signed-off-by: Felipe Milani <felmilani@gmail.com>
1 parent 1a0e8f9 commit 92c9f46

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

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

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

6670
</style>
6771

6872
<script>
73+
// query each hand element
74+
const secondHand = document.querySelector('.second-hand');
75+
const minHand = document.querySelector('.min-hand');
76+
const hourHand = document.querySelector('.hour-hand');
6977

78+
function setDate() {
79+
const now = new Date();
80+
const seconds = now.getSeconds();
81+
// we add 90 because of the offset to start the hand vertically
82+
const secondsDegrees = seconds*6 + 90;
83+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
84+
85+
const mins = now.getMinutes();
86+
const minsDegrees = mins*6 + 90;
87+
minHand.style.transform = `rotate(${minsDegrees}deg)`;
88+
89+
const hours = now.getHours();
90+
const hoursDegrees = hours*30 + 90;
91+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
92+
93+
}
94+
95+
// update the time each second
96+
setInterval(setDate, 1000);
7097

7198
</script>
7299
</body>

0 commit comments

Comments
 (0)