Facebook
From tak, 4 Years ago, written in HTML5.
Embed
Download Paste or View Raw
Hits: 174
  1.     <meta charset="utf-8">
  2.         <link rel="stylesheet" type="text/css" href="style.css" media="all">
  3.          
  4. </head>
  5. <center>
  6.     <div id="panel">
  7.     <h1 class="glow">00:00:00:00</h1>
  8.     <button id="start">Start</button>
  9.     <button id="stop">Stop</button>
  10.     <button id="clear">Clear</button>
  11.     </div>
  12.     var h1 = document.getElementsByTagName('h1')[0],
  13.     start = document.getElementById('start'),
  14.     stop = document.getElementById('stop'),
  15.     clear = document.getElementById('clear'),
  16.     miliseconds = 0, seconds = 0, minutes = 0, hours = 0,
  17.     t;
  18.  
  19. function add() {
  20.                 miliseconds++;
  21.         if (miliseconds >= 100) {
  22.                 miliseconds = 0;
  23.                 seconds++;
  24.     if (seconds >= 60) {
  25.         seconds = 0;
  26.         minutes++;
  27.         if (minutes >= 60) {
  28.             minutes = 0;
  29.             hours++;
  30.         }
  31.     }
  32.    
  33.         }
  34.     h1.textContent = (hours ? (hours > 9 ? hours : "0" + hours) : "00") + ":" + (minutes ? (minutes > 9 ? minutes : "0" + minutes) : "00") + ":" + (seconds > 9 ? seconds : "0" + seconds) + ":" + (miliseconds > 9 ? miliseconds : "0" + miliseconds);
  35.  
  36.     timer();
  37. }
  38. function timer() {
  39.     t = setTimeout(add, 10);
  40. }
  41.  
  42. start.onclick = timer;
  43. stop.onclick = function() {
  44.     clearTimeout(t);
  45. }
  46. clear.onclick = function() {
  47.     h1.textContent = "00:00:00:00";
  48.     milisecons = 0; seconds = 0; minutes = 0; hours = 0;
  49. }
  50.  
  51. </center>
  52. </body>
  53. </html>