Сергей Ракипов,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.tsifry{
display: inline-block;
width: 100px;
height: 40px;
margin: 10px 10px 10px 10px;
border-bottom: 1px solid #000;
text-align: center;
}
.skidka{
display: inline-block;
width: 200px;
height: 20px;
padding: 20px 20px 20px 20px;
border: 10px solid #4E82BE;
text-align: center;
cursor: pointer;
}
.skidka:hover{
border: 10px solid #132E5A;
}
.tekst{
display: inline-block;
width: 100px;
height: 20px;
text-align: center;
margin: 20px 0px 20px 0px;
}
</style>
</head>
<body>
<div class="tsifry">900</div>
<div class="skidka">Получить скидку?</div>
<script>
const animateNum = (elem, duration) => (from, to) => {
const beginTime = performance.now();
const animate = currentTime => {
let delta = (currentTime - beginTime) / duration;
delta = Math.min(1, delta);
let num = (from + (to - from) * delta) | 0;
elem.textContent = num;
delta == 1 || requestAnimationFrame(animate)
};
requestAnimationFrame(animate)
};
let tsifry = document.querySelector(".tsifry");
const skidka = document.querySelector(".skidka");
let tekst = document.querySelector(".tekst");
const duration = 1200;
const showNum = animateNum(tsifry, duration);
function skidkaFun(){
let y = +tsifry.innerHTML;
let x = y / 100 * 10;
let z = y - x;
showNum(y, z)
}
skidka.addEventListener("click", skidkaFun, {once : true});
</script>
</body>
</html>