ctoz Posted August 19, 2007 Share Posted August 19, 2007 With a lot of help—see recent posts—I've arrived at a function which changes two styles on a single element:function boxDC (boxname,display,color) { box = document.getElementById(boxname); box.style.display = display; box.style.color = color;}This is to be applied to a bunch of divs at regular intervals. I can do it primitive:function fireOne() { boxDC('jim','block','white');setTimeout('boxDC(\'jon\',\'block\',\'white\') ' ,60);setTimeout('boxDC(\'tom\',\'block\',\'white\') ' ,120);}but the bunch is bigger than 3 divs. So it looks like an array is needed, and a loop, which is where I'm still having problems:function fireOne() {// 32 divs oneWhite = new Array("jim","jon","tom", ... thru to "bob");function boxDC (boxname,display,color) { box = document.getElementById(boxname); box.style.display = display; box.style.color = color; } for (i = 0; i < oneWhite.length; i++) {setTimeout('boxDC(\'boxname\',\'block\',\'white\')', 60) }}looks close, but no cigar so far.cheersCT Link to comment Share on other sites More sharing options...
Synook Posted August 19, 2007 Share Posted August 19, 2007 Don't use loops, as then there will be no pause between your style changes, use setTimeout() itself to cause the function to run multiple times. function boxDC (display,color,current) { //Why need boxname when you have oneWhite?oneWhite = new Array("jim","jon","tom", ... thru to "bob"); //32 elementsbox = document.getElementById(oneWhite[current]);box.style.display = display;box.style.color = color;if (current != oneWhite.length - 1) {current++;setTimeout("boxDC('" + display + "','" + color + "'," + current + ")",60);}} And invoke it boxDC("block","white",0) where current always equals 0 (as you want to start at array index 0). Link to comment Share on other sites More sharing options...
ctoz Posted August 19, 2007 Author Share Posted August 19, 2007 Many Thanks. I'll go quite for a bit now. Link to comment Share on other sites More sharing options...
ctoz Posted August 19, 2007 Author Share Posted August 19, 2007 accidental post Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.