JSFiddle - React, Tailwind, and code Playground
by hammerbrostime
HTML
<body>
<div>Registration closes in <span id="time">05:00</span> minutes!</div>
</body>
CSS
#id {transition-duration:1s; transition-property: width height background-color;}
JavaScript
function startTimer(duration, display) {
var timer = duration, minutes, seconds;
setInterval(function () {
minutes = parseInt(timer / 60, 10)
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.textContent = minutes + ":" + seconds;
if (timer < 5) document.getElementById('time').style.backgroundColor = 'red';
else {
document.getElementById('time').style.backgroundColor = 'transparent';
}
if (--timer < 0) {
timer = duration;
}
}, 1000);
}
window.onload = function () {
var fiveMinutes = 7,
display = document.querySelector('#time');
startTimer(fiveMinutes, display);
};