var interval = 5000;
function reset() {
localStorage.endTime = +new Date + interval;
}
if (!localStorage.endTime) {
reset();
}
var remaining = localStorage.endTime - new Date;
setInterval(brojanje, 100)
function brojanje() {
if (remaining > 0) {
$('#timer').text(Math.floor(remaining / 1000));
} else {
return;
}
}
var interval = setInterval(brojanje, 100);
function brojanje() {
if (remaining > 0) {
$('#timer').text(Math.floor(remaining / 1000));
} else {
console.log('Alert and kill timer');
alert('STOP!');
clearInterval(interval);
}
}
Time remaining: