-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
39 lines (34 loc) · 996 Bytes
/
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
'use strict'
const secondsHand = document.querySelector('#second-hand')
const minutesHand = document.querySelector('#min-hand')
const hoursHand = document.querySelector('#hour-hand')
function startTime() {
const today = new Date()
let h = today.getHours()
let m = today.getMinutes()
let s = today.getSeconds()
m = checkTime(m)
s = checkTime(s)
document.querySelector('#clock').innerHTML = h + ':' + m + ':' + s
setTimeout(startTime, 1000)
}
function checkTime(i) {
if (i < 10) {
i = '0' + i
}
return i
}
function getTime() {
const timeInterval = 6
const now = new Date()
const seconds = now.getSeconds()
secondsHand.style.transform = 'rotate(' + seconds * timeInterval + 'deg)'
const minutes = now.getMinutes()
minutesHand.style.transform = `rotate(${
minutes * timeInterval + seconds / 10
}deg)`
const hours = now.getHours()
hoursHand.style.transform = 'rotate(' + (hours * 30 + minutes / 2) + 'deg)'
}
setInterval(getTime, 1000)
startTime()