Reputation: 13
How can I make when timediff is <=0 html freezes at 00:00 but javascript keeps countdown to minus so it can be removed when timdiff <= -90000 ?
<script>
var timer1;
function cdtd1() {
var sad1 = new Date();
var dolazak1 = new Date(sad1.getFullYear(),sad1.getMonth(),sad1.getDate(),13,37,00);
var timeDiff1 = dolazak1.getTime() - sad1.getTime();
if (timeDiff1 <= -90000) {
$("#Box1").remove();
}
var sekunde1 = Math.floor(timeDiff1 / 1000);
var minute1 = Math.floor(sekunde1 / 60);
var sati1 = Math.floor(minute1 / 60);
var dani1 = Math.floor(sati1 / 24);
sati1 %= 24;
minute1 %= 60;
sekunde1 %= 60;
$("#dani1Box").html(dani1);
$("#sati1Box").html(sati1 + ':');
$("#Ispis1").html('SOME TEXT '+ minute1 + ':' + sekunde1);
$("#sekunde1Box").html(sekunde1);
$("#timeDiff1").html(timeDiff1);
timer1 = setTimeout(cdtd1, 1000);
}
$(document).ready(function() {
cdtd1();
});
</script>
Here is the html, it's all in one box with spacing
HTML
<div id="Box1">
<h1 style="font-family:Helvetica;color:#FFFFFF;font-size:5px;"> </h1>
<div id="Ispis1"></div>
</div>
Upvotes: 0
Views: 70
Reputation: 1032
This should work
if(timeDiff1 <= 0){
$("#Ispis1").html('SOME TEXT 0:0');
}
Upvotes: 0
Reputation: 4873
I'm not very familiar with how jQuery works, but I'm guessing the following is where you change the HTML
$("#dani1Box").html(dani1);
$("#sati1Box").html(sati1 + ':');
$("#Ispis1").html('SOME TEXT '+ minute1 + ':' + sekunde1);
$("#sekunde1Box").html(sekunde1);
$("#timeDiff1").html(timeDiff1);
Assuming that's the case, then just make it
if(timeDiff1 >= 0){
$("#dani1Box").html(dani1);
$("#sati1Box").html(sati1 + ':');
$("#Ispis1").html('SOME TEXT '+ minute1 + ':' + sekunde1);
$("#sekunde1Box").html(sekunde1);
$("#timeDiff1").html(timeDiff1);
}
Then those will be skipped as soon as the timer is below zero.
Upvotes: 2