How To Exam Wise Countdown Timer Start
Solution 1:
Like I said in another thread, you need to remove the countdown from the LocalStorage. To achieve this you need to perform this action on an defined event, like a button click, or whatever.
functionresetCountdownInLocalStorage(){
localStorage.removeItem("seconds");
}
You can call this action, like I mentioned on for example the click event of your "Next" button, or on every Restart of the test.
For example if you want to call this action on your Next button and we assume that the button has the Id next
you can achieve the requested action by using this javascript snippet:
document.getElementById("next").onclick = function() {
localStorage.removeItem("seconds");
}
Or using the function from above:
document.getElementById("next").onclick = resetCountdownInLocalStorage;
Solution 2:
From your question i think you want a set of timers that will work independently. I have created an example. Please check this Fiddle
HTML
<divclass="timer"started="false"timerObj=""value="10">
Start Timer
<divid="timer1"></div></div><br><divclass="timer"started="false"timerObj=""value="10">
Start Timer
<divid="timer2"></div></div><br><divclass="timer"started="false"timerObj=""value="10">
Start Timer
<divid="timer3"></div></div>
CSS
.timer {
border-radius: 2px;
background: #73AD21;
padding: 20px;
width: 100px;
height: 20px;
}
JS
$(document).ready(function() {
functionmyTimer(resultDivId) {
var currentVal = $("#"+ resultDivId).parent().attr("value");
currentVal--;
if(currentVal == 0) {
var timerObj = $("#"+ resultDivId).parent().attr('timerObj');
clearInterval(timerObj);
}
$("#"+ resultDivId).html(currentVal);
$("#"+ resultDivId).parent().attr("value",currentVal);
}
$(".timer").click(function(){
if ($(this).attr('started') == "false") {
var currentDivId = $(this).children('div').prop("id");
var timerObj = setInterval(function(){ myTimer(currentDivId) }, 1000);
$(this).attr('started','true');
$(this).attr('timerObj',timerObj);
}
else {
var timerObj = $(this).attr('timerObj');
clearInterval(timerObj);
}
});
});
The timer will start when you click on div. It will stop if you click the div second time. You can also set separate count down for each div.
Post a Comment for "How To Exam Wise Countdown Timer Start"