Advertisement
kangjaz

jam.js

Oct 19th, 2018
2,146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function animation(span) {
  2.    span.className = "turn";
  3.    setTimeout(function() {
  4.       span.className = "";
  5.    }, 700);
  6. }
  7.  
  8. function jam(){
  9.    setInterval(function() {
  10.       var waktu = new Date();
  11.       var jam = document.getElementById('jam');
  12.       var hours = waktu.getHours();
  13.       var minutes = waktu.getMinutes();
  14.       var seconds = waktu.getSeconds();
  15.       
  16.       if (waktu.getHours() < 10) {
  17.          hours = '0' + waktu.getHours();
  18.       }
  19.       if (waktu.getMinutes() < 10) {
  20.          minutes = '0' + waktu.getMinutes();
  21.       }
  22.       if (waktu.getSeconds() < 10) {
  23.         seconds = '0' + waktu.getSeconds();
  24.       }
  25.  
  26.       jam.innerHTML =  '<span>'+hours+'</span>'
  27.                                   + '<span>'+minutes+'</span>'
  28.                                   + '<span>'+seconds+'</span>';
  29.  
  30.       var spans = jam.getElementByTagName('span');
  31.       animation(spans[2]);
  32.       if (seconds == 0) animation(spans[1]);
  33.       if (minutes == 0 && seconds == 0) animation(spans[0]);
  34.  
  35.    }, 1000);
  36. }
  37.  
  38. jam();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement