<!DOCTYPE html>
<html>
<body>
<div>Registration closes in <span id="time">05:00</span> minutes!</div>
<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);
}
var display = document.querySelector('#time');
var timeinseconds=60*5; // 60 seconds X 5 minutes
startTimer(timeinseconds, display);
</script>
</body>
</html>
No comments:
Post a Comment