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