Таймер обратного отсчета
Код функции в head и вызов в body
Самостоятельно
207.00K
Category: programmingprogramming

Таймер обратного отсчета. JavaScript

1. Таймер обратного отсчета

Разработка Латыповой Е.В.

2. Код функции в head и вызов в body

<script>
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 < 0) {
timer = duration;
}
}, 1000);
}
window.onload = function () {
var fiveMinutes = 60 * 10,
display = document.querySelector('#time');
startTimer(fiveMinutes, display);
};
</script>
<body>
<div>закрытие игры через <span
id="time">10:00</span> минут!</div>
</body>

3. Самостоятельно


Создать игру с таймером времени на 10 минут.
English     Русский Rules