Hi,
I have the following code for a countdown timer:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<div id="timer"></div>
<script>
var currentTime = new Date().getTime();
var days = 11;
var hours = 6;
var minutes = 32;
var seconds = 44;
var targetTime = currentTime + (days * 24 * 60 * 60 * 1000) + (hours * 60 * 60 * 1000) + (minutes * 60 * 1000) + (seconds * 1000);
setInterval(function() {
var currentNewTime = new Date().getTime();
var secondsLeft = (targetTime - currentNewTime) / 1000;
var days = parseInt(secondsLeft / 86400);
days = (days < 10) ? "0"+days : days;
secondsLeft = secondsLeft % 86400;
var hours = parseInt(secondsLeft / 3600);
hours = (hours < 10) ? "0"+hours : hours;
secondsLeft = secondsLeft % 3600;
var minutes = parseInt(secondsLeft / 60);
minutes = (minutes < 10) ? "0"+minutes : minutes;
var seconds = parseInt(secondsLeft % 60);
seconds = (seconds < 10) ? "0"+seconds : seconds;
if (secondsLeft > 0) {
document.getElementById("timer").innerHTML = days+":"+hours+":"+minutes+":"+seconds;
}
}, 1000);
</script>
</body>
</html>
It works fine on Chrome but it lags on Firefox. Every 5-10 seconds, it stops, then it jumps 2 seconds down. Any idea what might cause that and how to fix it?
Thanks.