Число на странице уменьшается на глазах — например, «осталось мест».
timer.<style>
/* Стили для элемента таймера */
.timer {
color: #000000;
font-size: 25px;
font-family: 'Arial',Arial,sans-serif;
line-height: 1;
font-weight: 600;
letter-spacing: 0.5px;
background-position: center center;
border-color: transparent;
border-style: solid;
/* Другие стили */
}
</style>
<script>
const timerElement = document.querySelector('.timer');
function saveStyles(element) {
const styles = getComputedStyle(element);
return styles.cssText;
}
function updateTimer() {
let time = 4500;
const savedStyles = saveStyles(timerElement);
function countdown() {
time -= 1;
timerElement.textContent = time;
if (time === 356) {
time = 4500;
timerElement.style.cssText = savedStyles;
}
if (time !== 356) {
setTimeout(countdown, 0.2);
}
}
countdown();
}
window.onload = () => {
updateTimer();
};
</script>