Created
January 23, 2021 16:35
-
-
Save MrCordeiro/e3f90ee77dde56aad4e5a6d3266abdbc to your computer and use it in GitHub Desktop.
timer-progress-bar
This file contains 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
/** | |
* Displays the remaining time before date | |
*/ | |
timer = function () { | |
// Set the date we're counting down to | |
const startDate = new Date(Date.UTC(2020, 9, 5)); | |
const endDate = new Date(Date.UTC(2021, 0, 15)); | |
const now = new Date(); | |
const timeTotal = endDate - startDate; | |
const timeLeft = endDate - now; | |
// update countdown | |
const days = Math.floor(timeLeft / (1000 * 60 * 60 * 24)); | |
document.getElementById("daysLeft").innerHTML = days; | |
// Update progress bar | |
const progressBar = document.querySelector(".progress-bar"); | |
const pctFilled = Math.floor(100 * (1 - timeLeft/timeTotal)) ; | |
progressBar.setAttribute("aria-valuenow", pctFilled); | |
progressBar.style.width = pctFilled + "%"; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment