View Full Version : Changing background Image???
Romulus
01-26-2003, 03:05 AM
I saw a page recently that had a different background image every time that you visited it. Well, for about twelve times anyway...
I was wondering if anyone can tell me what kind of script could do this on a page. I figured it had something to do with cookies as well, so the browser knows if the person has been there before and would switch the image if the answer is yes.
I'd appreciate any help with this.
CRASH_OVERRIDE
01-26-2003, 03:17 AM
I wouldnt see any need for cookies, unless you wanted to be sure that the same bckgrnd isnt shown twice in a row.
This might work:
var img=new Array();
img[0]='image1.gif';
img[1]='image2.gif';
img[2]='image3.gif';
...
document.getElementByTagName('body').style.backgroundImage=img[math.floor(math.random()*img.length)];
Or something like that...
Ooops, big booboo. :o
justame
01-26-2003, 03:17 AM
rom...
just a nottt® to sure that this one below uses just a cookies®...'cept it tis just a random® background script...hehehe...
http://www.codingforums.com/showthread.php?s=&threadid=3779&highlight=random+background
just a goodluck® n' hoping it helps til the pros come just a long® ifin' ya need help customizin' it...:O)))
Romulus
01-26-2003, 04:00 AM
Yeah, I would want to make sure that it was a different image each time. Although the random number scripts are handy, I find that you need a fairly large selection of images to choose from to make it seem like it's going through them all. If you have, say five, it seems that a couple come up way too much.
However, that's not to say that someone is going to be sitting there opening the page over and over again, I guess I just want to know that if they did, it would be different for every image in the array. Until they got to the end.
And does that script have to be used for the background?? Or is it possible to use it for a specific image on the page as long as you give it an ID or something???
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.