Random image?

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
dataminer78
Beginner
Beginner
Posts: 2
Joined: Fri Mar 09, 2007 10:55 am

Post by dataminer78 »

Hello! I wanted to use the code presented above in div section of my homepage (to switch background images), but I couldn't cope with it. I created a simple webpage, put images 0.jpg, 1.jpg in the same folder but the code isn't working. Would you have any suggestions?

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<head>

<title>Title</title>

<Script language="JavaScript">
function getRandomImage() 
{ 
var upperLimit = 1; 
var imagePath = ""; 
var baseName = ""; 
var imageType = ".jpg"; 
var randomNum = Math.round(Math.random()*upperLimit); 
var fileName = imagePath + baseName + randomNum + imageType; 
return fileName; 
} 
</script>

<style type="text/css">
#headr {
   padding: 0;
   margin: 0;
   position: relative;
   height: 200px;
   background: #3371A3 url(getRandomImage()); no-repeat bottom center;}
</style>

</head>
<body>

<div id="headr" >
Text 
</div>

</body>
</html>
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

Hi,

Hi, are you talking about the demo page with the Item Random Image function on it?

That random image function only works with the Milonic Menu, it is to force a menu item to use a random image.

If you're looking for something just on a webpage you can try ask or google search

js random background images

Ruth
dataminer78
Beginner
Beginner
Posts: 2
Joined: Fri Mar 09, 2007 10:55 am

Post by dataminer78 »

OK, thank you for suggestion.
EDIT: I found an answer on my question on http://www.webmasterworld.com/forum83/4146.htm ("Random image without PHP", script by ocallaghans)
Post Reply