Skip to content

Instantly share code, notes, and snippets.

@devfaysal
Last active February 4, 2021 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devfaysal/be0accbda0d74b7ea4029d84e190ac1b to your computer and use it in GitHub Desktop.
Save devfaysal/be0accbda0d74b7ea4029d84e190ac1b to your computer and use it in GitHub Desktop.
Countdown Timer
var endDate = new Date("Feb 5, 2021 12:00:00 GMT-0800").getTime();
var timer = setInterval(function() {
let now = new Date().getTime();
let t = endDate - now;
if (t >= 0) {
let days = Math.floor(t / (1000 * 60 * 60 * 24));
let hours = Math.floor((t % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
let mins = Math.floor((t % (1000 * 60 * 60)) / (1000 * 60));
let secs = Math.floor((t % (1000 * 60)) / 1000);
document.getElementById("timer-days").innerHTML = days +
"<span class='countDownTimerLabel'>DAY(S)</span>";
document.getElementById("timer-hours").innerHTML = ("0"+hours).slice(-2) +
"<span class='countDownTimerLabel'>HR(S)</span>";
document.getElementById("timer-mins").innerHTML = ("0"+mins).slice(-2) +
"<span class='countDownTimerLabel'>MIN(S)</span>";
document.getElementById("timer-secs").innerHTML = ("0"+secs).slice(-2) +
"<span class='countDownTimerLabel'>SEC(S)</span>";
} else {
document.getElementById("countDownTimer").innerHTML = "Sharks Game Used Jersey is on Sale!";
}
}, 1000);
#shopify-section-1612415745b96c6cb5{
background: #00778a;
padding-top: 15px;
margin-bottom:0;
}
#countDownTimer {
color: #fff;
background: #00778a;
font-size: 3rem;
text-align: center;
padding-top: 10px;
padding-bottom: 15px;
}
.countDownTimerLabel {
font-size: 1.5rem;
padding-left: 0.25rem;
}
@media only screen and (max-width: 600px) {
#countDownTimer {
color: #fff;
font-size: 2rem;
text-align: center;
}
.countDownTimerLabel {
font-size: 1rem;
padding-left: 0.12rem;
}
}
<p id="countDownTimer">
<span style="color:#fff; font-size: 1.5rem; display:block;">Sharks Game Used Jersey Sale Starts Friday 12:00 pm PST</span>
<br>
<span id="timer-days"></span>
<span id="timer-hours"></span>
<span id="timer-mins"></span>
<span id="timer-secs"></span>
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment