-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
55 lines (39 loc) · 1.9 KB
/
script.js
File metadata and controls
55 lines (39 loc) · 1.9 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var innerCircle = document.getElementById("inner-circle");
//create minute scale
for(let i = 0; i<60; i++){
var diameter = document.createElement("div");
var M = document.createElement("div");
diameter.setAttribute("style", "position: absolute; top: 49.5%; left: 0%; width: 100%; height: 1%;");
M.setAttribute("style", "position:absolute;background-color: black; top: 0%; left:97%; width:3%; height:100%;");
diameter.style.transform = `rotate(${i*360/60}deg)`;
diameter.appendChild(M);
innerCircle.appendChild(diameter);
}
//create hour scale
for(let i = 0; i<12; i++){
var diameter = document.createElement("div");
var H = document.createElement("div");
diameter.setAttribute("style", "position: absolute; top: 48.5%; left: 0%; width: 100%; height: 3%;");
H.setAttribute("style", "position:absolute;background-color: black; top: 0%; left:95%; width:5%; height:100%;");
diameter.style.transform = `rotate(${i*360/12}deg)`;
diameter.appendChild(H);
innerCircle.appendChild(diameter);
}
var secondHand = document.getElementById("second-hand");
var minuteHand = document.getElementById("minute-hand");
var hourHand = document.getElementById("hour-hand");
//set hands function (using current time)
function setHands(){
var d = new Date();
var sec = d.getSeconds();
var min = d.getMinutes();
var hour = d.getHours()%12; // % needed because there is only 12 hours on analog watch
var secondHandAngle = (sec*360)/60-90; //-90 because CSS set hands horizontaly when angle is 0deg
var minuteHandAngle = (min*360)/60-90;
var hourHandAngle = (hour*360)/12+(min*30)/60-90; //(min*30)/60 added simulate real analog watch
secondHand.style.transform = `rotate(${secondHandAngle}deg)`;
minuteHand.style.transform = `rotate(${minuteHandAngle}deg)`;
hourHand.style.transform = `rotate(${hourHandAngle}deg)`;
}
setHands();
setInterval(function(){setHands();}, 1000); //call setHands() each 1 second