Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
May 25, 2012, 08:07:29 AM

Pages: [1]   Go Down
  Print  
Author Topic: random background images with css?  (Read 296 times)
Lisaleese
Trekkie
**
Offline Offline

Posts: 11


WWW
« on: February 20, 2003, 02:12:00 AM »

Hi all-

I have been using CSS for background images on my pages

Body
{background-image: url(image.jpg;
repeat: repeat-y;}

for example, and I'm wondering if there is any way to put in some kind of script - CGI, java, whatever - so I can randomize my images each time the page is reloaded - or at least once a day?

Thank you in advance!

Lisa

P.S.  I am a complete script newbie, so....
Logged
stephan
Guest
« Reply #1 on: February 20, 2003, 02:27:00 AM »

It can be done, in a few ways.

CSS isn't the easiest, or the most possible!

Here's a solution I took off another site.

If you don't understand it, or don't know how to, just write back.

 
code:
 <html>
<head>
<title>Random Backs</title>
<HEAD>
</HEAD>
<script language="JavaScript">
var theImages = new Array();
theImages[0] = '1.gif'
theImages[1] = '2.gif'
theImages[2] = '3.gif'
theImages[3] = '4.gif'
//    and so on...

var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
  preBuffer = new Image()
  preBuffer.src = theImages
}
var whichImage = Math.round(Math.random()*(p-1));
document.write('<body background="'+theImages[whichImage]+'">');
</script>
</body>
</html>

Logged
Pages: [1]   Go Up
  Print  
 
Jump to: