JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Slider</title>
<link href="font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
</head>
<body>
<section id="timer">
<div class="days">0</div>
<div class="hours">0</div>
<div class="minutes">5</div>
<div class="seconds">00</div>
</section>
</body>
</html>
CSS
*{
margin: 0;
padding: 0;
border:0;
}
body{
background-color: darkslategray;
width: 100%;
}
#timer{
width:75%;
margin: 0 auto;
overflow: auto;
}
.days,.hours,.minutes,.seconds{
color: white;
font-size: 500%;
float: left;
width: 12%;
margin: 2%;
padding: 3%;
text-align: center;
border: 1px solid black;
border-radius: 10%;
}
.days{
background-color: firebrick;
}
.hours{
background-color: burlywood;
}
.minutes{
background-color:forestgreen;
}
.seconds{
background-color:cornflowerblue;
}
.rotate{
animation-name: rotate;
animation-timing-function: ease;
animation-duration: 0.7s;
}
@keyframes rotate{
0% {transform: rotateX(0deg);}
100% {transform: rotateX(360deg);}
}
@-webkit-keyframes rotate{
0% {transform: rotateX(0deg);}
100% {transform: rotateX(360deg);}
}
JavaScript
var timer= document.getElementById("timer").children;
var edDate = new Date();
var endDate = edDate.setMinutes(edDate.getMinutes()+5) ;
setInterval(time, 1000);
function time() {
var currentDate = new Date().getTime();
var countdowntime = endDate-currentDate;
var days = Math.floor((((countdowntime/1000)/60)/60)/24);
var hours = Math.floor((((countdowntime/1000)/60)/60))%24;
var minutes = Math.floor(((countdowntime/1000)/60))%60;
var seconds = Math.floor((countdowntime/1000))%60;
timer[0].textContent = days;
timer[1].textContent = hours;
timer[2].textContent = minutes;
timer[3].textContent = seconds;
timer[3].classList.add("rotate");
setTimeout(function(){f(3);},500);
function f(x){timer[x].classList.remove("rotate")}
if(timer[3].textContent==59){
timer[2].classList.add("rotate");
setTimeout(function(){f(2);},500);}
}