Click to See Complete Forum and Search --> : loop, layer & images....solved!!!!!!!


leechun
05-18-2003, 04:45 PM
hello helpful people:

thanks for all your inputs regarding my previous post on "loop, layers and images". you have been most helpful:) after some Brain squeezing, i have came up with a solution that works, i thought i might share this with you and maybe you can provide some feedback. ok, here it goes....

/*create layers using loop like this*/

var img_name = "sec_img";
var div_name = "sec";
var img_full_name;
var div_full_name;
var index;

for(index=0;index<somevalue; index++)
{
div_full_name = div_name + index;
img_full_name = img_name + index;

document.write('<div id = '+div_full_name+' style = "position:absolute;top:0px;left:0px">');

document.write('<img id = '+img_full_name+'>');

document.write('</div>')
}

/*then alter aspects of the imges like this*/

function change_img_src()
{

var rand = Math.floor(Math.random() * 100) % 2;
var img_name = "sec_img";
var img_full_name = img_name + ((Math.floor(Math.random() * 100) % somevalue) + 1);

if(rand) eval(img_full_name).src = img1.src;
else eval(img_full_name).src = img2.src;

timer4 = setTimeout("change_img_src()", 500);

}


I apologise in advance if this method seem a bit brutal;)

peace,
CHUN

Jona
05-19-2003, 01:33 PM
That's cool. Glad you got it worked out. ;) However, might I suggest something? I would change your document.write()'s to document.writeln()'s, because document.writeln() puts a \n at the end of your document.write()'s automatically.

Note: This won't make your code work better, but it's just something that I would do. ;)

Seeya,
Jona

leechun
05-19-2003, 03:50 PM
thanks again, will look into that. :)

cheers

CHUN