View Full Version : CSS Backgrounds


sanehni
07-12-2003, 07:27 PM
Ok I don't know if this is possible in ANY background let alone CSS but does anyone know if there is a code that whenever someone goes to my site the background image changes randomly from a pre selected group of images?

If not does anyone know if this is possible in normal backgrounds??

kicker91
07-12-2003, 08:38 PM
search the javascript source (http://www.javascript.internet.com), they're sure to have something ;)

sanehni
07-12-2003, 11:18 PM
Thank you for your advice. I found a code that was basically what I wanted but I couldn't get it to work since I am javascript illiterate and my background is basically a small image in the bottom right corner... i have no clue what i am doing. But thanks.

MaGiCSuN
07-12-2003, 11:20 PM
could you maybe then post the code you are trying to use? Thanks

Love,
Mirna

sanehni
07-12-2003, 11:26 PM
Below is the code I want to use. I'm not sure that I will ever be able to get it to work since I use a small image carefully placed as my background via CSS to keep the layout friendly to different resolutions. I basically want to be able to have the picture change whenever someone acesses my site.
If there is any help or advice you can offer it would be more than appreciated.
Shannon

<!-- FOUR STEPS TO INSTALL RANDOM IMAGES:

1. Paste the first code into the HEAD of your HTML document
2. Add the onLoad event handler to the BODY tag
3. Place the last script in the BODY of your HTML document
4. Save the 7 background images to your directory -->

<!-- STEP ONE: Paste this code into HEAD of your document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Tim Wallace -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

today=new Date();
jran=today.getTime();
var number = 7;
var random_number="";
var image="";
var text_color="";
ia=9301;
ic=49297;
im=233280;
jran = (jran*ia+ic) % im;
random_number = Math.ceil( (jran/(im*1.0)) *number);
// Loads the appropriate image and text color based on random number.
if (random_number==1) {
text_color="000000";
image="paper.gif";
}
if (random_number==2) {
text_color="000000";
image="wood.gif";
}
if (random_number==3) {
text_color="000000";
image="clouds.gif";
}
if (random_number==4) {
text_color="000000";
image="faces.gif";
}
if (random_number==5) {
text_color="000000";
image="marble.gif";
}
if (random_number==6) {
text_color="000000";
image="question.gif";
}
if (random_number==7) {
text_color="000000";
image="plain.gif";
}
// End -->
</SCRIPT>
</HEAD>

<!-- STEP TWO: Add this onLoad event handler to the BODY tag -->

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
document.open();
document.write("<BODY BACKGROUND='"+image+"' TEXT='"+text_color+"'>");
document.write("<CENTER></CENTER>");
// End -->
</SCRIPT>

<!-- STEP THREE: Place this script in the BODY of the HTML document -->

<BODY>

<FORM>
<INPUT TYPE="button" VALUE="Reload Page" onClick="window.location='r-images.html'">
</FORM>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
document.write("<CENTER>Background Image: <FONT SIZE=-1>("+image+")</FONT></CENTER>");
// End -->
</SCRIPT>

<!-- STEP FOUR: Save the 7 background images to your directory -->

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 2.38 KB -->

kicker91
07-12-2003, 11:38 PM
follow all the instructions, like where it says "put this in <body>" some of your codes are in the wrong place =[

--mod--
please move to javascript =D

sanehni
07-12-2003, 11:44 PM
Yeah I know that (for the most part) but I need to know if there is anyway I can specify where I want the image. Cause if I can't then I can't use it. Like if I wanted to make sure the BG was fixed in the bottom right corner could I do that? And how?
That code I posted is straight off the site that I got it from so I haven't touched anything to screw it up yet.