I have written a jQuery plugin and all is well except the script pauses when you switch to a different tab. The body of the script is a setInterval()
with a 1ms delay.
var count = setInterval( function() {
if (iMil <= 0) {
if (iS == 0) {
if (iMin == 0) {
if (iH == 0) {
// DONE
milliseconds.text(0);
clearInterval(count);
} else {
iH--;
iMin = 59;
iS = 59;
iMil = 999;
}
} else {
iMin--;
iS = 59;
iMil == 999;
}
} else {
iS--;
iMil = 999;
}
} else {
iMil-=4; // Make up for ms lost doing calculations
}
hours.text(iH);
minutes.text(iMin);
seconds.text(iS);
if (iMil >= 10 && iMil < 100) {
milliseconds.text('0'+iMil);
} else if (iMil >= 0 && iMil < 10) {
milliseconds.text('00'+iMil);
} else if (iMil == -1) {
milliseconds.text('000');
} else {
milliseconds.text(iMil);
}
}, 1 );
Is there a way to run this regardless which tab you are on?