<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Countdown numbers HTML CSS Js</title>
<!-- Box icons CDN -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/boxicons@latest/css/boxicons.min.css">
<link rel="stylesheet" href="https://unpkg.com/boxicons@latest/css/boxicons.min.css">
</head>
<body>
<div class="wrapper">
<div class="container">
<i class='bx bxs-landscape'></i>
<span class="num" data-val="400">000</span>
<span class="text">Memories</span>
</div>
</div>
</body>
</html>
@import url('https://fonts.googleapis.com/css2?family=Merriweather:wght@900&family=Poppins&display=swap');
*
{
padding: 0;
margin: 0;
box-sizing: border-box;
}
body
{
height: 100vh;
background-color: #121317;
display: flex;
justify-content: center;
align-items: center;
}
/* .wrapper
{
border: 1px solid white;
position: absolute;
width: 80vw;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
display: flex;
} */
.container
{
/* width: 28vmin;
height: 28vmin; */
display: flex;
flex-direction: column;
justify-content: space-around;
padding: 1em 2em;
position: relative;
font-size: 16px;
border-radius: 0.5em;
background-color: #21242b;
border-bottom: 10px solid #18f98f;
}
i
{
color: #18f98f;
font-size: 2.8em;
text-align: center;
}
span.num
{
color: #ffffff;
text-align: center;
font-weight: 600;
font-size: 3em;
font-family: 'Merriweather', serif;
}
span.text
{
color: #e0e0e0;
text-align: center;
font-weight: 400;
font-family: 'Poppins', sans-serif;
}
let valueDisplays = document.querySelectorAll(".num");
let interval = 5000;
// console.log(valueDisplays);
valueDisplays.forEach((valueDisplay) => {
let startValue = 0;
let endValue = parseInt(valueDisplay.getAttribute("data-val"));
// console.log(endValue);
let duration = Math.floor(interval / endValue);
let counter = setInterval(function(){
startValue += 1;
valueDisplay.textContent = startValue;
if(startValue == endValue)
{
clearInterval(counter);
}
});
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.