Can anybody see why the distcount() function doesn't render the race distance here?
and in the HTML:
Code:
var race = 2000;
var counter = setInterval(function(){distcount(race)}, 1000); //1000 will run it every 1 second
function distcount(race)
{
var inrace = race;
if (inrace > 0)
{
clearInterval(counter);
return;
}
document.getElementById("race").innerHTML = inrace + "yds";
}
var runners = 6;
$(function() {
$('#clickme').click(function() {
if(racestart == false){
$('#book').animate({
left: '+=50'
}, 5000, function() {
});
racestart = true;
}
});
});
$(function() {
$.perSecond = function() {
if(race){
for(looper = 0; looper < 2; looper++){
looperplus = looper+1;
disttravelled[looper] += racepace[looper];
//document.write(namers[looper]+": "+disttravelled[looper]+"<br/><br/>");
if(racepace[looper] > bestdistance) {
bestdistance = racepace[looper];
}
$('#h'+looperplus).animate({ left: '+='+racepace[looper]/10+"px" }, 1000, function() { });
}
race -= bestdistance;
} else {
alert("Race ended");
}
};
});
function raceGo(){
//document.write("runners: "+runners+"<br/><br/>");
bestdistance = 0;
var int = self.setInterval(function(){$.perSecond()},1000);
racestart = true;
}
and in the HTML:
Code:
<span id="race"></span>