-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.js
More file actions
29 lines (23 loc) · 716 Bytes
/
clock.js
File metadata and controls
29 lines (23 loc) · 716 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
29
function clock(){
var date = new Date()
console.log(date)
var hours = date.getHours()
var minutes = date.getMinutes()
var seconds = date.getSeconds()
if(hours>12){
hours -= 12
}
var secondDeg = seconds/60 * 360
var minuteDeg = (minutes * 60 + seconds) / 3600 * 360
var hourDeg = (hours*3600 + minutes*60 + seconds) / (12 * 3600) * 360
console.log(secondDeg)
console.log(minuteDeg)
console.log(hourDeg)
document.querySelector('.secondHand').style.transform = `rotate(${-90+secondDeg}deg)`
document.querySelector('.hourHand').style.transform = `rotate(${-90+hourDeg}deg)`
document.querySelector('.minuteHand').style.transform = `rotate(${-90+minuteDeg}deg)`
}
clock()
setInterval(function(){
clock()
},1000)