I have never programmed in jquery. I’m using JQuery Countdown plugin for
to have a countdown when i call a php page but the timer doesn’t restart.
I need to write a restart function to call by the ‘onExpiry’ event of the JQuery Countdown plugin. This is the script that i have on a html page.
I’m following this post :
Auto Restart/Reset countdown timer
but i think that the solution in that post doesn’t work because is about dates.
I need to restart for a random period of maximum 2 hours.
Thanks…..
$(document).ready(function () {
function randRange() {
var newTime = Math.floor(Math.random() * 30001) + 10000;
return newTime;
}
function toggleSomething() {
$('#timeval').load('ajaxTime.php?randval=' + Math.random());
clearInterval(timer);
lollo = parseInt(randRange());
timer = setInterval(toggleSomething, lollo);
$('#msg').fadeOut("slow").countdown({ *onExpiry:?????* until : +(lollo / 1000),
format : 'HMS',
layout : '<div id="timer">' + '<div class="timer_numbers">{hnn}:{mnn}:{snn}</div>' + '</div>'
}).fadeIn("slow");
}
var timer = setInterval(toggleSomething, 1000);
});
EDIT:
I solved :
$('#msg').countdown({until: +(lollo/1000), onExpiry: function() { setTimeout(function() { $('#msg').countdown('change', {until: +((lollo/1000) - 1)}); }, 1000); }, format: 'HMS', layout:
'<div id="timer">'+
'<div class="timer_numbers">{hnn}:{mnn}:{snn}</div>'+
'</div>'
});
If anyone has a better solution please contact me pro-zac31[at]libero.it …. !!! Thanks 🙂
How about this: