2016-12-22 3 views
0

다음 질문으로 넘어갈 때, 타이머가 처음부터 시작됩니다. 즉, 시험을 시작할 때 - n 타이머를 5 분으로 설정했지만 이전 할 때 다음 질문은 각 질문마다 n에 대해 5 분에서부터 시작됩니다. 퀴즈를 시작하면 내 전체 퀴즈에 대한 타이머를 설정하고 새로운 시간 (예 : 5 분)마다 모든 질문에 다시 설정하지 않습니다. "나는 다음 질문으로 이동하고 때"카운트 다운 타이머 재설정 문제

function startTimer(duration, display) { 
    var start = Date.now(), 
     diff, 
     minutes, 
     seconds; 
    function timer() { 
     // get the number of seconds that have elapsed since 
     // startTimer() was called 
     diff = duration - (((Date.now() - start)/1000) | 0); 

     // does the same job as parseInt truncates the float 
     minutes = (diff/60) | 0; 
     seconds = (diff % 60) | 0; 

     minutes = minutes < 10 ? "0" + minutes : minutes; 
     seconds = seconds < 10 ? "0" + seconds : seconds; 

     display.textContent = minutes + ":" + seconds; 

     if (diff <= 0) { 
      // add one second so that the count down starts at the full duration 
      // example 05:00 not 04:59 
      start = Date.now() + 1000; 
     } 
    }; 
    // we don't want to wait a full second before the timer starts 
    timer(); 
    setInterval(timer, 1000); 
} 

window.onload = function() { 
    var fiveMinutes = 60 * 5, 
     display = document.querySelector('#time'); 
    startTimer(fiveMinutes, display); 
}; 
<body> 
    <div>Registration closes in <span id="time"></span> minutes!</div> 
</body> 
+0

왜 'javascript'가 아닌 'servlets' 태그가 있습니까? –

+0

sry 그것은 자바 스크립트 태그 –

+0

sry 될 것입니다, 태그는 자바 스크립트 것입니다 –

답변

0

당신 어때요

는 다음 질문으로 이동? 전체 페이지로드?

창이 다시로드되면 타이머를 재설정하는 window.onload 이벤트가 있습니다. 다음 질문으로 이동하면 창이 다시로드됩니까?

질문에 대한 추가 정보가 필요합니다.