-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·30 lines (21 loc) · 802 Bytes
/
script.js
File metadata and controls
executable file
·30 lines (21 loc) · 802 Bytes
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
const HOURHAND = document.querySelector("#hour");
const MINUTEHAND = document.querySelector("#minute");
const SECONDHAND = document.querySelector("#second");
function runTheClock() {
var date = new Date();
// Get the current time with date object.
let hr = date.getHours();
let min = date.getMinutes();
let sec = date.getSeconds();
// Create the hour.
let hrPos = (hr*360/12)+(min*(360/60)/12);
// Create the minute.
let minPos = (min*360/60)+(sec*(360/60)/60);
// Create the second.
let secPos = sec*360/60;
// Add the calculate deg to the element
HOURHAND.style.transform = "rotate(" + hrPos + "deg)";
MINUTEHAND.style.transform = "rotate(" + minPos + "deg)";
SECONDHAND.style.transform = "rotate(" + secPos + "deg)";
}
var interval = setInterval(runTheClock, 1000);