-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
64 lines (49 loc) · 1.96 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
'use strict';
const numberHours = document.querySelector('.number-hours');
const barSeconds = document.querySelector('.bar-seconds');
const numberElement = [];
const barElement = [];
for (let i = 1; i <= 12; i++) {
numberElement.push(`<span style="--index:${i};"><p>${i}</p></span>`);
}
numberHours.insertAdjacentHTML('afterbegin', numberElement.join(''));
for (let i = 1; i <= 60; i++) {
barElement.push(`<span style="--index:${i};"><p></p></span>`);
}
barSeconds.insertAdjacentHTML('afterbegin', barElement.join(''));
const handHours = document.querySelector('.hand.hours');
const handMinutes = document.querySelector('.hand.minutes');
const handSeconds = document.querySelector('.hand.seconds');
function getCurrentTime() {
const date = new Date();
const currentHours = date.getHours();
const currentMinutes = date.getMinutes();
const currentSeconds = date.getSeconds();
const currentMilliseconds = date.getMilliseconds();
handHours.style.animationDelay = `-${
(43200 / 12) * (currentHours % 12) + ((43200 / 12) * currentMinutes) / 60
}s`;
// Since animation-duration is set to 3600s at .hands-box .minutes
// We should transform [0, 60] -> [0s, 3600s]
// Example 1: handle points on 0 -> `-0s`
// Example 2: handle points on 3 -> `-180s`
// Example 3: handle points on 60 -> `-3600s`
// So formula is: 3600 / 60 * currentMinutes + correctionForSeconds
// correctionForSeconds is number between 0 and 3600 / 60
handMinutes.style.animationDelay = `-${
(3600 / 60) * currentMinutes + ((3600 / 60) * currentSeconds) / 60
}s`;
handSeconds.style.animationDelay = `-${
1000 * currentSeconds + currentMilliseconds
}ms`;
}
const dateWindow = document.querySelector('.date-window');
function getCurrentDate() {
let date = new Date();
let currentDate = date.getDate();
console.log(currentDate);
dateWindow.innerText = currentDate;
}
getCurrentDate();
getCurrentTime();
// setInterval(getCurrentTime, 1000);