-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
75 lines (58 loc) · 1.82 KB
/
script.js
File metadata and controls
75 lines (58 loc) · 1.82 KB
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
var hoursContainer = document.querySelector('.hours')
var minutesContainer = document.querySelector('.minutes')
var secondsContainer = document.querySelector('.seconds')
var tickElements = Array.from(document.querySelectorAll('.tick'))
var last = new Date(0)
last.setUTCHours(-1)
var tickState = true
function updateTime () {
var now = new Date
var lastHours = last.getHours().toString()
var nowHours = now.getHours().toString()
if (lastHours !== nowHours) {
updateContainer(hoursContainer, nowHours)
}
var lastMinutes = last.getMinutes().toString()
var nowMinutes = now.getMinutes().toString()
if (lastMinutes !== nowMinutes) {
updateContainer(minutesContainer, nowMinutes)
}
var lastSeconds = last.getSeconds().toString()
var nowSeconds = now.getSeconds().toString()
if (lastSeconds !== nowSeconds) {
//tick()
updateContainer(secondsContainer, nowSeconds)
}
last = now
}
function tick () {
tickElements.forEach(t => t.classList.toggle('tick-hidden'))
}
function updateContainer (container, newTime) {
var time = newTime.split('')
if (time.length === 1) {
time.unshift('0')
}
var first = container.firstElementChild
if (first.lastElementChild.textContent !== time[0]) {
updateNumber(first, time[0])
}
var last = container.lastElementChild
if (last.lastElementChild.textContent !== time[1]) {
updateNumber(last, time[1])
}
}
function updateNumber (element, number) {
//element.lastElementChild.textContent = number
var second = element.lastElementChild.cloneNode(true)
second.textContent = number
element.appendChild(second)
element.classList.add('move')
setTimeout(function () {
element.classList.remove('move')
}, 990)
setTimeout(function () {
element.removeChild(element.firstElementChild)
}, 990)
}
setInterval(updateTime, 100)