tirabytes

HTML: Timer

Apr 1st, 2019
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.16 KB | None | 0 0
  1. <html style="display:block; height:100%; margin:0; padding:0"
  2. <head>
  3. <style type="text/css">
  4.     html {
  5.         background: #000000;
  6.         }
  7.         #timer {
  8.         padding: 100px;
  9.         font-family: sans-serif;
  10.         font-weight: bold;
  11.         color: #FFFFFF;
  12.         }
  13. </style>
  14. </head>
  15. <body style="display:table; width:100%; height:100%; margin:0; padding:0">
  16.  
  17. <div style="display:table-cell; width:100%; height:100%; text-align:center; vertical-align:middle">
  18.     <span id="timer" style="font-size:400pt; font-kerning:none"></span>
  19. </div>
  20. <script type="text/javascript">
  21. function checklength(i) {
  22.     'use strict';
  23.     if (i < 10) {
  24.        i = "0" + i;
  25.    }
  26.    return i;
  27. }
  28.  
  29. var minutes, seconds, count, counter, timer;
  30. count = 1805; //seconds
  31. counter = setInterval(timer, 1000);
  32.  
  33. function timer() {
  34.    'use strict';
  35.    count = count - 1;
  36.    minutes = checklength(Math.floor(count / 60));
  37.    seconds = checklength(count - minutes * 60);
  38.    if (count < 0) {
  39.        clearInterval(counter);
  40.        return;
  41.    }
  42.    document.getElementById("timer").innerHTML = '' + minutes + ':' + seconds + ' ';
  43.    if (count === 0) {
  44.        location.reload();
  45.    }
  46. }
  47. </script>
  48. </body>
  49. </html>
Add Comment
Please, Sign In to add comment