Good point Bob90, might as well declare an object and be specific when creating variables though to protect the global environment:
Code:
var showDiv={
divs:['d1','d2','d3','d4','d5'], //Set divisions
i:3000, //Set Interval
c:0,t:0,
hide:function(){
for (var i=0; i<this.divs.length; i++)
document.getElementById(this.divs[i]).style.display = 'none';
},
doIt:function(){
this.hide();
document.getElementById(this.divs[this.c%this.divs.length]).style.display = 'block';
this.c++;
},
init:function(){
clearInterval(this.t);
var o=this, g=function(){o.doIt();};
g();
o.t=setInterval(g, o.i);
}
};
showDiv.init();
With setInterval, as Bob90 suggests, it can now be turned on and off. This will stop it:
Code:
clearInterval(showDiv.t);
This starts/resumes it:
Bookmarks