개발/javascript
javascript 에서 timer 기능 사용하기
LukeHan1128
2023. 5. 30. 20:00
반응형
function startTimer(duration, display){
var timer = duration, seconds;
var interval = setInterval(function(){
seconds = parseInt(timer % 60, 10);
seconds = seconds < 10 ? "0" + seconds : seconds;
display.textContent = seconds;
if(timer === 0){
clearInterval(interval);
}
if(--timer < 0){
timer = duration;
}
}, 1000);
}
startTimer(60, document.querySelector('#timeCount'));
반응형