-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
48 lines (39 loc) · 1.26 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
'use strict';
window.addEventListener('load', handler);
function handler() {
var date = new Date();
setTime(date);
setTimeout(handler, 1000);
}
function setTime(date) {
var time = [date.getHours(), date.getMinutes(), date.getSeconds()];
var timeUnit = ['hours', 'minutes', 'seconds'];
timeUnit.forEach( (elem, i) => {
var cell = document.getElementById(elem);
if(cell.parentNode.scrollTop) {
cell.children[0].innerHTML = cell.children[1].innerHTML;
cell.parentNode.scrollTop = 0;
}
document.getElementById(elem).children[1].innerHTML =
`${parseInt(time[i] / 10)}${time[i] % 10}`;
if(cell.children[0].innerHTML != cell.children[1].innerHTML) {
animate(cell);
}
});
}
function checkTime() {
var timeUnit = ['hours', 'minutes', 'seconds'];
timeUnit.forEach( (elem, i) => {
var cell = document.getElementById(elem);
if(cell.children[0].innerHTML != cell.children[1].innerHTML) {
cell.children[0].innerHTML = cell.children[1].innerHTML;
}
});
}
function animate(elem) {
elem.classList.toggle('scroll-top');
setTimeout( () => {
elem.classList.toggle('scroll-top');
checkTime();
}, 996)
}