-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (31 loc) · 967 Bytes
/
app.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
let hours = document.querySelector('.hours');
let minutes = document.querySelector('.minutes');
let seconds = document.querySelector('.seconds');
function rotate(){
let date = new Date();
let getHours = date.getHours();
let getMinutes = date.getMinutes();
let getSeconds = date.getSeconds();
let sF = getSeconds / 60;
let mF = (sF + getMinutes) / 60;
let hF = (mF + getHours) / 12;
let sD = Math.floor(sF * 360);
let mD = Math.floor(mF * 360);
let hD = Math.floor(hF * 360);
//reset transition if 0 deg
if(sD == 0 ){
seconds.style.transition = null;
minutes.style.transition = null;
hours.style.transition = null;
}
else{
//add transition if > 0 deg, to make smooth
seconds.style.transition = '1s';
minutes.style.transition = '.8s';
hours.style.transition = '.4s';
}
hours.style.transform = `rotate(${hD}deg)`;
minutes.style.transform = `rotate(${mD}deg)`;
seconds.style.transform = `rotate(${sD}deg)`;
}
setInterval(rotate, 1000);