SHARE
TWEET

Untitled

a guest Apr 18th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <style>
  2. output {
  3.   font-size: 50px;
  4.   font-weight: bold;
  5. }
  6. </style>
  7.  
  8.  
  9.  
  10. <div style="z-index:1" onload="voiceWelcome()">
  11. <button id="start">Start</button>
  12. <button id="stop">Stop</button>
  13. <button id="reset">Reset</button>
  14. <br><br><br><br>
  15. <output>00:00:00</output>
  16. </div>
  17.  
  18.  
  19. <script>
  20. const startBtn = document.querySelector('#start');
  21. const stopBtn = document.querySelector('#stop');
  22. const resetBtn = document.querySelector('#reset');
  23. const output = document.querySelector('output');
  24.  
  25. const speechSynth = window.speechSynthesis;
  26. let timeRead = false;
  27.  
  28. let now = 0;
  29. let interval = null;
  30.  
  31. function startTimer() {
  32.  
  33.   let elapsedMil = Date.now() - now;
  34.  
  35.   let mil = (elapsedMil).toFixed(0) % 100;
  36.   let sec = Math.floor(elapsedMil/1000) % 60;
  37.   let min = Math.floor(elapsedMil/60000) % 60;
  38.  
  39.   mil = padTime(mil);
  40.   sec = padTime(sec);
  41.   min = padTime(min);
  42.  
  43.   function padTime(num) {
  44.     if (num < 10) {
  45.       num = "0" + num;
  46.     }
  47.     return num;
  48.   }
  49.  
  50.   output.textContent = min + ":" + sec + ":" + mil;
  51. }
  52.  
  53. function start() {
  54.   now = Date.now();
  55.   interval = window.setInterval(startTimer, 10);
  56. }
  57.  
  58. function stop() {
  59.   window.clearInterval(interval);
  60. }
  61.  
  62. function reset() {
  63.   output.textContent = "00:00:00";
  64. }
  65.  
  66. startBtn.addEventListener('click', start);
  67. stopBtn.addEventListener('click', stop);
  68. resetBtn.addEventListener('click', reset);
  69.  
  70. </script>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top