JavaScript: Last setInterval lasts longer then expected
I asked for help before on how to fix something with my javascript code, I
have that fixed now however is there a problem with my code? Because the
last array stays on for longer than 1 second, it stays on for like 5
seconds. Is this because I'm resetting the array or is this normal in
Javascript?
function Background()
{
var Backgrounds = [
'#333', '#777', '#999', '#CCC'
],
Max_Backgrounds = Backgrounds.length,
Background_Stage = -1;// Yes, it's meant to be -1 so when
background_stage++; is called it will make it 0 thus start at the
beginning of the array.
setInterval(function() {
if(Background_Stage >= Max_Backgrounds) Background_Stage = -1;
$('body').css('background', Backgrounds[Background_Stage++]);
}, 1000);
}
No comments:
Post a Comment