Thread: countdown
View Single Post
Old 04-04-2009, 08:58 PM   #9 (permalink)
Krik
The Contributor
 
Join Date: Feb 2009
Posts: 65
Thanks: 0
Krik is on a distinguished road
Default

I thought I should give you some code that has some performance improvement.

You may want to ignore this till you get the above working.

In my previous code for some dumb reason I made the function work like a loop. I am not sure why I did that as a loop would run faster.

So the following code uses a for loop and in so doing condenses the code more.

Also each loop does takes a fraction of time to run. So I have made the code reduce the timer by a fraction of a second for each additional row that must be looped through.

HTML Code:
<script type="text/javascript">
var rowcount = 4;
function multiCountDown(){

var endcount = true;
    for (var nextrow = 1; nextrow <= rowcount; nextrow++) {
        if (document.getElementById('mycount'+nextrow).innerHTML != 0) {
            document.getElementById('mycount'+nextrow).innerHTML = document.getElementById('mycount'+nextrow).innerHTML - 1;
            endcount = false;
        }
    }
    if(!endcount) {
        var sectimer = Math.round(1000 - (rowcount / 2 ));
        counter = setTimeout("multiCountDown();", sectimer);
    }
    else {
        clearTimeout(counter);
    }
}
</script>
Krik is offline  
Reply With Quote
The Following User Says Thank You to Krik For This Useful Post:
allworknoplay (04-04-2009)