-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathfunction-jam-digital
40 lines (34 loc) · 1.01 KB
/
function-jam-digital
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
```
function animation(span) {
span.className = "turn";
setTimeout(function() {
span.className = "";
}, 700);
}
function jam(){
setInterval(function() {
var waktu = new Date();
var jam = document.getElementById('jam');
var hours = waktu.getHours();
var minutes = waktu.getMinutes();
var seconds = waktu.getSeconds();
if (waktu.getHours() < 10) {
hours = '0' + waktu.getHours();
}
if (waktu.getMinutes() < 10) {
minutes = '0' + waktu.getMinutes();
}
if (waktu.getSeconds() < 10) {
seconds = '0' + waktu.getSeconds();
}
jam.innerHTML = '<span>'+hours+'</span>'
+ '<span>'+minutes+'</span>'
+ '<span>'+seconds+'</span>';
var spans = jam.getElementByTagName('span');
animation(spans[2]);
if (seconds == 0) animation(spans[1]);
if (minutes == 0 && seconds == 0) animation(spans[0]);
}, 1000);
}
jam();
```