tduva

Countdown

Oct 15th, 2018
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.84 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3. <style>
  4. #time {
  5.     color: white;
  6.     font-family: Arial;
  7.     font-size: 100px;
  8. }
  9. </style>
  10. <script>
  11. function startTimer(duration, display) {
  12.     var timer = duration, minutes, seconds;
  13.     var intv = setInterval(function () {
  14.         minutes = parseInt(timer / 60, 10);
  15.         seconds = parseInt(timer % 60, 10);
  16.  
  17.         minutes = minutes < 10 ? "0" + minutes : minutes;
  18.        seconds = seconds < 10 ? "0" + seconds : seconds;
  19.  
  20.        display.textContent = minutes + ":" + seconds;
  21.  
  22.        if (--timer < 0) {
  23.         clearInterval(intv);
  24.        }
  25.    }, 1000);
  26. }
  27.  
  28. window.onload = function () {
  29.    var time = parseInt(window.location.hash.substring(1)),
  30.        display = document.querySelector('#time');
  31.    startTimer(time, display);
  32. };
  33. </script>
  34. </html>
  35. <body>
  36. <div id="time"></div>
  37. </body>
  38. </html>
Advertisement
Add Comment
Please, Sign In to add comment