A Pen by Sierra Gregg

Thumbnail
This awesome code was written by 13thDayCoder, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright 13thDayCoder ©
  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>A Pen by  Sierra Gregg</title>
  
  
  
  
  
</head>

<body>

  <p role="timer" id="clock"></p>
<p id="progress"></p>
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/13thDayCoder/a-pen-by-sierra-gregg-vZbEog */
var start = performance.now();
var duration = 25 * 60 * 1000;
var elapsed = 0;
var clock = document.getElementById('clock');
var prog = document.getElementById('progress');
clock.innerHTML = duration;


function step(timestamp) {
  // if (!start) start = timestamp;
  var progress = duration - elapsed;
  elapsed++;
  var seconds = Math.floor((progress / 1000) % 60);
  var minutes = Math.floor((progress / 1000 / 60) % 60);
  clock.innerHTML = minutes + ":" + seconds;
  prog.innerHTML = progress;
  if (elapsed > 0) {
    window.requestAnimationFrame(step);
  }
}

window.requestAnimationFrame(step);

Comments