Skip to content

Instantly share code, notes, and snippets.

@catwhocode
Created February 21, 2022 22:56
Show Gist options
  • Save catwhocode/3132cefd654ff8378a5e9f625182e3e4 to your computer and use it in GitHub Desktop.
Save catwhocode/3132cefd654ff8378a5e9f625182e3e4 to your computer and use it in GitHub Desktop.
JS: Simple Progress Bar
<!DOCTYPE html>
<html>
<head>
<title>CountDown</title>
<!-- source: http://crowdforthink.com/blogs/how-to-create-a-countdown-timer-with-progress-bar-in-javascript -->
</head>
<body>
<progress value="0" max="3600" id="pbar" ></progress>
<p id="counting">3600</p>
<button id="start" onclick="start_countdown()">Start CountDown</button>
<script type="text/javascript">
function start_countdown(){
var reverse_counter = 3600;
var downloadTimer = setInterval(function(){
document.getElementById("pbar").value = 3600 - --reverse_counter;
if (reverse_counter <= 0)
clearInterval(downloadTimer);
document.getElementById("counting").innerHTML= reverse_counter;
}, 1000);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment