At first my countdown timer has no pause and resume function and the timer runs just fine. Now I just added the feature, have no problem pausing but having problem resuming the time. The time just would not display from where it was and countdown from there on. How do I change my codes?
$('#pause').click(function(){
// Get current minutes and seconds //
var text = $('#countdown').html();
var min_sec = text.split(":");
pause_minutes = min_sec[0];
pause_seconds = min_sec[1];
// Stop the timer //
clearTimeout(stop_start);
// Hide pause button, show the play button //
$('#pause').hide();
$('#cont').show();
});
// continue button is clicked //
$('#cont').click(function(){
$('#cont').hide();
$('#pause').show();
// Pass in pause_minutes and pause_seconds //
resume_time(pause_minutes, pause_seconds);
});
function resume_time(pause_minutes, pause_seconds){ // e.g: 1 , 30
var start_time = new Date();
end_time.setMinutes(start_time.getMinutes() + pause_minutes);
end_time.setSeconds(start_time.getSeconds() + pause_seconds);
update_timer();
}
function update_timer(){
var current_time = new Date();
var remaining_time = new Date();
remaining_time.setTime(end_time.getTime() - current_time.getTime());
var minutes = remaining_time.getMinutes();
var seconds = remaining_time.getSeconds();
if(seconds < 10){
seconds = '0'+seconds.toString();
}
$("#countdown").text(minutes+":"+seconds);
// call itself every second if //
if(minutes == '0' && seconds == '00'){
$('.big_words').html('Sorry, times up');
$('.overlay').show();
setTimeout(function(){
location.reload();
}, 2000);
exit;
}
stop_start = setTimeout(update_timer,1000);
}