I need a stopwatch/timer to countdown. I’m trying to use Kellis Havers stopwatch jQuery plugin and change it to countdown.
But can’t figure out how to make it substract instead of add seconds, tried changing the ‘second++;’ to ‘second–;’ but got this result= 00:03:0-1. It says in the comments that parseInt() is not working, so i figure it something with the seconds is written in 01 02 03 04 etc.
But I am not yet good enough to understand how to get it to countdown.
function do_time() {
// parseInt() doesn't work here...
hour = parseFloat(h.text());
minute = parseFloat(m.text());
second = parseFloat(s.text());
second++;
if(second > 59) {
second = 0;
minute = minute + 1;
}
if(minute > 59) {
minute = 0;
hour = hour + 1;
}
h.html("0".substring(hour >= 10) + hour);
m.html("0".substring(minute >= 10) + minute);
s.html("0".substring(second >= 10) + second);
}
}
})(jQuery);
parseIntwill work fine if you include 10 as a second argument.Change to:
jsFiddle