[thelist] generating random image in css

Luther, Ron ron.luther at hp.com
Thu Jun 9 07:43:52 CDT 2005


Ron Pringle noted:

> Is there any way to randomize that background image so that a new 
> image appears when the page is loaded/reloaded? I use ASP/VBScript on 
> the site.


Hi Ron,


Yes. (I used to do something very similar on my site when it was running

on a Winbox.)

What I did was write three different CSS files, (differentiated with a 
numeric suffix: "thing1.css", "thing2.css", "thing3.css"), each with a 
different color scheme and a different image.  [Not quite 'zengarden' 
but kinda fun anyway.]

Then, in my main, 'index.asp', page I added a small routine that would 
select a random number "x", (with a value of "1", "2", or "3") and 
physically copy [thing"x".css] and overwrite a file called [thing.css] 
on the server.

All of the pages within my site would then call the 'thing.css' file.


(It shouldn't be too tough to modify something like that to just rewrite

the background image if you use a similar (numeric suffix style) naming 
convention for your background images.)


What I liked about this was that anyone's initial visit would get a 
random color scheme but that color scheme would also 'persist' 
throughout their stay ... unless they hit a 'hard' refresh of course.

Also, since each visitor would, most likely, cache the css file ... 
I could have simultaneous visitors, (yeah right, like I get that 
many!), who would each see the site in a different color scheme.

{Actually, I even thought of offering it up for a 'site review' here 
at that time just to hear someone complain about the 'crappy orange' 
and have other folks ask 'Orange? What orange?' ... I thought that 
might be fun - but then - I'm like that!}  


;-)



HTH,

RonL.


More information about the thelist mailing list