Random intervaled timer
Random intervaled timer
Hi, I am trying to build a timer that counts down from a randomlly set number and decrease at random timed intervals! I have managed to get the timer to set and start at a random number!
I am having trouble getting it to set the random interval time between changes! Anyone able to help? As an added bonus I would also like to be able to remember the number it was on if the page is refreshed etc!
Thanks
Code is currently:
<script type="text/javascript">
$(document).ready(function(){
/* delay function */
jQuery.fn.delay = function(time,func){
return this.each(function(){
setTimeout(func,time);
});
};
// GENERATE A RANDOM NUMBER FOR DURATION //
var durationLow = 1000;
var durationHigh = 5000;
var adjustedDuration = (parseFloat(durationHigh) - parseFloat(durationLow)) + 1;
var durationRand = Math.floor(Math.random()*durationHigh) + parseFloat(durationLow);
// END //
jQuery.fn.countDown = function(settings,to) {
settings = jQuery.extend({
startFontSize: '24px',
endFontSize: '24px',
duration: durationRand,
startNumber: 10,
endNumber: 0,
callBack: function() { }
}, settings);
return this.each(function() {
if(!to && to != settings.endNumber) { to = settings.startNumber; }
//set the countdown to the starting number
$(this).text(to).css('fontSize',settings.startFontSize);
//loopage
$(this).animate({
'fontSize': settings.endFontSize
},settings.duration,'',function() {
if(to > settings.endNumber + 1) {
$(this).css('fontSize',settings.startFontSize).text(to - 1).countDown(settings,to - 1);
}
else
{
settings.callBack(this);
}
});
});
};
// GENERATE A RANDOM NUMBER FOR QUANTITY //
var numLow = 199;
var numHigh = 629;
var adjustedHigh = (parseFloat(numHigh) - parseFloat(numLow)) + 1;
var numRand = Math.floor(Math.random()*adjustedHigh) + parseFloat(numLow);
// END //
$('#countdown').countDown({
startNumber: numRand,
callBack: function(me) {
$(me).text('OUT').css('color','#F00');
}
});
});
</script>