-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
92 lines (65 loc) · 2.85 KB
/
script.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
var ID = document.getElementById.bind(document);
this.onload = function()
{
var sec, min, hr, clock, secondHand, minuteHand, hourHand, secDeg, minDeg, hrDeg, i, top, right, spanDeg, radius;
//loading clock ----->
function loadClock()
{
sec = new Date().getSeconds() + 2;
min = new Date().getMinutes();
hr = new Date().getHours();
clock = ID("clock-wrapper");;
secondHand = ID("clock-second");
minuteHand = ID("clock-minute");
hourHand = ID("clock-hour");
secDeg = (sec * 6);
minDeg = (min + (sec / 60)) * 6;
hrDeg = ((hr - 12) * 30) + ((min / 60) * 30);
}
document.addEventListener("visibilitychange", loadClock);
loadClock();
radius = ((clock.offsetWidth - 20) / 2)
//starting clock ----->
setInterval(function()
{
secondHand.style.WebkitTransform = "rotate(" + secDeg + "deg)";
minuteHand.style.WebkitTransform = "rotate(" + minDeg + "deg)";
hourHand.style.WebkitTransform = "rotate(" + hrDeg + "deg)";
secondHand.style.transform = "rotate(" + secDeg + "deg)";
minuteHand.style.transform = "rotate(" + minDeg + "deg)";
hourHand.style.transform = "rotate(" + hrDeg + "deg)";
secDeg += 6; minDeg += 0.1; hrDeg += 0.1/60;
hr = new Date().getHours();
if (hr > 11)
ID("am-pm").innerHTML = "PM";
else
ID("am-pm").innerHTML = "AM";
}, 1000);
//creating hours strokes (with the <span> tag) ----->
for (i = 0, spanDeg = 0; i < 12; i++, spanDeg += 30)
{
top = (Math.cos(spanDeg * Math.PI/180) * (radius - 10)).toFixed(6);
right = (Math.sin(spanDeg * Math.PI/180) * (radius - 10)).toFixed(6);
clock.insertAdjacentHTML("beforeend", "<span class='digits d" + i + "'></span>");
clock.getElementsByClassName("d"+i)[0].style.WebkitTransform = "rotate(" + spanDeg + "deg)";
clock.getElementsByClassName("d"+i)[0].style.transform = "rotate(" + spanDeg + "deg)";
clock.getElementsByClassName("d"+i)[0].style.top = ((radius - 9.5) - top) + "px";
clock.getElementsByClassName("d"+i)[0].style.right = ((radius - 1.5) - right) + "px";
}
//creating minutes strokes (with the <span> tag) ----->
for (i = 0, spanDeg = 0; i < 60; i++, spanDeg += 6)
{
if (spanDeg % 30 != 0)
{
top = (Math.cos(spanDeg * Math.PI/180) * (radius - 10)).toFixed(6);
right = (Math.sin(spanDeg * Math.PI/180) * (radius - 10)).toFixed(6);
clock.insertAdjacentHTML("beforeend", "<span class='mini-digits md" + i + "'></span>");
clock.getElementsByClassName("md"+i)[0].style.WebkitTransform = "rotate(" + spanDeg + "deg)";
clock.getElementsByClassName("md"+i)[0].style.transform = "rotate(" + spanDeg + "deg)";
clock.getElementsByClassName("md"+i)[0].style.top = ((radius - 4) - top) + "px";
clock.getElementsByClassName("md"+i)[0].style.right = ((radius - 0.5) - right) + "px";
}
else continue;
}
}
//END ----->