forked from Axe-Pearl/Mini-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (23 loc) · 1.04 KB
/
script.js
File metadata and controls
29 lines (23 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const hourHand = document.getElementById('hour');
const minHand = document.getElementById('min');
const secHand = document.getElementById('sec');
function updateClock() {
const now = new Date();
// Get current time units
const seconds = now.getSeconds();
const minutes = now.getMinutes();
const hours = now.getHours();
// Calculate degrees for rotation
// (Value / Total) * 360 degrees
const secDeg = ((seconds / 60) * 360);
const minDeg = ((minutes / 60) * 360) + ((seconds/60)*6); // Add seconds for smooth movement
const hourDeg = ((hours / 12) * 360) + ((minutes/60)*30); // Add minutes for smooth movement
// Apply styles
secHand.style.transform = `translateX(-50%) rotate(${secDeg}deg)`;
minHand.style.transform = `translateX(-50%) rotate(${minDeg}deg)`;
hourHand.style.transform = `translateX(-50%) rotate(${hourDeg}deg)`;
}
// Run the function every 1000 milliseconds (1 second)
setInterval(updateClock, 1000);
// Run it once immediately so the clock doesn't wait 1 second to start
updateClock();