| If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below. | |
|
 |
06-26-2004, 02:48 AM
|
#1
|
|
Junior Member
Join Date: Jun 2004
Location: New Zealand
Posts: 7
|
Changing background image
Is it possible to have a page load a different background image everytime it loads? And is it possible to do this client side?
Thanks, Kimber
|
|
|
06-27-2004, 03:42 PM
|
#2
|
|
Senior Member
Join Date: Jan 2004
Location: I Forgot
Posts: 459
|
Code:
<script>
var a=new Array('1.jpg','2.jpg','3.jpg');
document.body.style.background=a[Math.floor(Math.random()*a.length)];
</script>
Should do the trick, i am busy so i can't test it and i have a dendancy of mixing up php functions with javacript ones so i am not responsible if it doesn't work.
|
|
|
06-27-2004, 08:37 PM
|
#3
|
|
Junior Member
Join Date: Jun 2004
Location: New Zealand
Posts: 7
|
thanks, I'll give it a try 
|
|
|
06-27-2004, 09:11 PM
|
#4
|
|
Junior Member
Join Date: Jun 2004
Location: New Zealand
Posts: 7
|
Hmmmm, sorry, didn't work. And I know stuff all about javascript or php, so I don't know how to fix it. But at least I know it 'can' be done, so I know what to search for. Thanks 
|
|
|
06-28-2004, 10:52 PM
|
#5
|
|
Junior Member
Join Date: Nov 2003
Location: USA
Posts: 28
|
Is it possible using this instead of php or JS from a CSS?
|
|
|
06-29-2004, 09:47 AM
|
#6
|
|
Administrator
Join Date: Oct 2002
Location: Canada
Posts: 1,196
|
Random Background Script
azlatin2000 - close but no cigar.
You will have to edit the following with your own filenames and alter the random number limit to be (1 - # of images).
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Random Background</title>
<meta http-equiv="DESCRIPTION"
content="random background demo">
</head>
<body>
<script language="JavaScript"
type="text/javascript">
<!--
// This must go between body tags - NOT IN THE HEAD SECTION
// Edit per your own site structure and number of images
image = new Array
// Build array of image filenames
image[0]="firstone.gif"
image[1]="nextone.gif"
image[2]="anotherone.gif"
image[3]="lastone.gif"
// Create a random number 0 to 3
// (remember array element 1 is image[0])
index = (Math.round((Math.random()*3)))
// Set background style with random array element
document.body.style.background="url("+image[index]+") repeat"
//-->
</script>
<h1>Random Background Demo</h1>
<script language="JavaScript"
type="text/javascript">
<!--
document.write("Using background image "+image[index])
</script>
-->
</body>
</html>
DE
__________________
David Elliott
Ask a better question - get a better answer!
|
|
|
06-29-2004, 05:47 PM
|
#7
|
|
Junior Member
Join Date: Jun 2004
Location: New Zealand
Posts: 7
|
Ooh, thanks heaps, will give it a go 
|
|
|
06-29-2004, 06:05 PM
|
#8
|
|
Senior Member
Join Date: Jan 2004
Location: I Forgot
Posts: 459
|
Oh, yeah i forgot about the url() thing. I was planning to use the old non css way then in the middle of writing the code i changed my mind.
|
|
|
07-04-2004, 11:37 PM
|
#9
|
|
Junior Member
Join Date: Jun 2004
Location: New Zealand
Posts: 7
|
Finally got round to implementing it, and thanks heaps, it worked.
|
|
|
07-05-2004, 12:24 PM
|
#10
|
|
Probationary
Join Date: Jun 2004
Posts: 2
|
can you please tell me the background code just the simple one that remains constant. can anyone tell me where i could find these types of simple codes? Thank you very much to whoever helps, I need it
|
|
|
07-06-2004, 02:54 AM
|
#11
|
|
Senior Member
Join Date: Dec 2003
Location: Holland
Posts: 186
|
Code:
<html>
<head>
<style type="text/css">
body{
background: URL(image.jpg);
}
</style>
</head>
<body>
content of the page
</body>
</html>
Save this as .html file, and the image you want as background-image, is, in this example, called image.jpg, that image-file MUST be in the same folder as the .html file.
Pascal
__________________
Always remember:
"the best prediction of future behaviour is past behaviour"
:D :*D:
On holiday from the 10th of Juli till 26th of Juli.
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 08:37 AM.
Powered by vBulletin® Version 3.8.6 Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.

© Evrsoft.com. All Rights Reserved.
|
|
|