Created
February 21, 2022 22:56
-
-
Save catwhocode/3132cefd654ff8378a5e9f625182e3e4 to your computer and use it in GitHub Desktop.
JS: Simple Progress Bar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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