0
How do I get a countdown with jquery but only in minutes and second -> 04:00 03:59 03:58... with option to stop, restart and increase and decrease the time someone could give me an example?
code:
var tempo = $("#tempo").text("05:00");
tempo = new Number();
// Tempo em segundos
tempo = 300;
function startCountdown() {
// Se o tempo não for zerado
if ((tempo - 0) >= 0) {
// Pega a parte inteira dos minutos
var min = parseInt(tempo / 60);
// Calcula os segundos restantes
var seg = tempo % 60;
// Formata o número menor que dez, ex: 08, 07, ...
if (min < 10) {
min = "0" + min;
min = min.substr(0, 2);
}
if (seg <= 9) {
seg = "0" + seg;
}
// Cria a variável para formatar no estilo hora/cronômetro
horaImprimivel = min + ':' + seg;
//JQuery pra setar o valor
$("#tempo").html(horaImprimivel);
// Define que a função será executada novamente em 1000ms = 1 segundo
setTimeout('startCountdown()', 1000);
// diminui o tempo
tempo--;
} else {
}
}
the code counts backwards but how do I pause and restart?
Do you know Javascript? What have you tried to do?
– Woss
I tried to use Countdown with jquery but n I was able to use without date by the plugin documentation since there are only examples to count leaving for a specific date.
– Alan
It’s something that’s not hard to do even with pure JS
– Isac
Again the question: do you know Javascript? Do not try to use jQuery without knowing Javascript.
– Woss
I know a little bit of Javascript, I know a little bit of jquery
– Alan
Start with Javascript as Anderson indicated. You’ll need to use at least
setInterval
,clearInterval
. Then manipulate the minutes and seconds manually– Isac
An aid: https://jsfiddle.net/44d1h9xw/
– novic
edited my question with my countdown code that is already working need now pause and restart.
– Alan