Skip to content

Instantly share code, notes, and snippets.

@Flowbaseco
Last active April 20, 2023 02:33
Show Gist options
  • Save Flowbaseco/f2a6224b5ef93355bed7df4bc6a80ef7 to your computer and use it in GitHub Desktop.
Save Flowbaseco/f2a6224b5ef93355bed7df4bc6a80ef7 to your computer and use it in GitHub Desktop.
<script>
// Countdown Timer by Flowbase
// Set the target date and time
var target_date = new Date("December 31, 2023 23:59:59").getTime();
// Update the countdown timer every second
var countdown_timer = setInterval(function() {
// Get the current date and time
var current_date = new Date().getTime();
// Calculate the remaining time in milliseconds
var distance = target_date - current_date;
// Calculate the remaining days, hours, minutes, and seconds
var day = 1000 * 60 * 60 * 24;
var hour = 1000 * 60 * 60;
var minute = 1000 * 60;
var second = 1000;
// Add the ID to your HTML/Webflow text elements
document.getElementById('days').innerText = Math.floor(distance / (day));
document.getElementById('hours').innerText = Math.floor((distance % (day)) / (hour));
document.getElementById('minutes').innerText = Math.floor((distance % (hour)) / (minute));
document.getElementById('seconds').innerText = Math.floor((distance % (minute)) / second);
// Check if the countdown is complete
if (distance < 0) {
clearInterval(countdown_timer);
document.getElementById('days').innerText = '0';
document.getElementById('hours').innerText = '0';
document.getElementById('minutes').innerText = '0';
document.getElementById('seconds').innerText = '0';
// You can display an element at the end of the countdown with this ID
document.getElementById('message').style.display = 'block';
}
}, 1000);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment