Simple Hoops countdown
by ian_smithz
HTML
<p id="countdown"></p>
CSS
#countdown {
display: flex;
align-items: center;
justify-content: center;
font-family: "archivo_narrowbold", sans-serif;
color: #e70026;
font-size: 2rem;
background-color: #0053a0;
color: #fff;
padding: 0.5rem;
min-height: 40px;
}
#countdown span {
font-size: 1rem;
padding: 0.5rem;
}
/* for demo only */
body {font-size: 16px;}
JavaScript
// Set the date we're counting down to
var countDownDate = new Date("Nov 25, 2018 23:59:59").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now an the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result in the element with id="countdown"
document.getElementById("countdown").innerHTML = days + " <span>Tage</span> " + hours + " <span>Std.</span> " +
minutes + " <span>Min.</span> " + seconds + " <span>Sek.</span>";
// If the countdown is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("countdown").innerHTML = "Leider ist diese Aktion abgelaufen";
}
}, 1000);