Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-25-2006, 03:13 PM   PM User | #1
stilsen
New to the CF scene

 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
stilsen is an unknown quantity at this point
cant get javascript document.write images to be under other content

this is sort of a javascript/html/css question:

im using a javascript to randomly position many small images on the page,
and i want them to be in the background relative to other content on the page. for example, the command below is run a bunch of times in a javascript in my header, which i call from the body:

document.write('<img src="./images/' + img_rnd[i] + '" style="z-index: 1; position: absolute; left:' + x[i] + '; top: ' + y[i] + '; width: ' + img_width + '; height: ' + img_height + ';"></img>');

despite setting z-indexes to 2 for my divs/layrs/tables in the body, i cant get them to overlap the images positioned by the document.write call.

is there a better/different way to get these images to be "in the background"?

thanks,
sam
stilsen is offline   Reply With Quote
Old 08-25-2006, 03:34 PM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
In my oppinion you should have used DOM methods to create the elements and their attributes, not the obsolate document.write() method
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 08-25-2006, 06:46 PM   PM User | #3
stilsen
New to the CF scene

 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
stilsen is an unknown quantity at this point
so what your saying is use statements like??

document.images[i].src="./images/" + img_rnd[i];
document.images[i].height=img_width;
document.images[i].width=img_height;

can i use the DOM to position, resize, and layer the images
behind other content?
stilsen is offline   Reply With Quote
Old 08-28-2006, 10:14 AM   PM User | #4
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
Could be something like this:
Code:
//inside your i loop
...
var root=document.getElementById('mydiv'+i);//the node where to append the image
var pic=document.createElement('img');
var att=[
['width',img_width],['height',img_height],['src','./images/'+img_rnd[i]]
]
for(var j=0;j<att.length;j++){
pic.setAttribute(att[j][0],att[j][1]);
}
var css=[
['position','absolute'],['zIndex',1],['left',x[i]+'px'],['top',y[i]+'px']
]
for(var j=0;j<css.length;j++){
pic.style[css[j][0],css[j][1]];
}
...
root.appendChild(pic);
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:59 AM.


Advertisement
Log in to turn off these ads.