Webmaster Forums


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.



Reply
Old 06-26-2004, 02:48 AM   #1
Kimber
Junior Member
 
Join Date: Jun 2004
Location: New Zealand
Posts: 7
Kimber is on a distinguished road
Default 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
Kimber is offline   Reply With Quote
Old 06-27-2004, 03:42 PM   #2
azlatin2000
Senior Member
 
azlatin2000's Avatar
 
Join Date: Jan 2004
Location: I Forgot
Posts: 459
azlatin2000 is on a distinguished road
Default

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.
azlatin2000 is offline   Reply With Quote
Old 06-27-2004, 08:37 PM   #3
Kimber
Junior Member
 
Join Date: Jun 2004
Location: New Zealand
Posts: 7
Kimber is on a distinguished road
Default

thanks, I'll give it a try
Kimber is offline   Reply With Quote
Old 06-27-2004, 09:11 PM   #4
Kimber
Junior Member
 
Join Date: Jun 2004
Location: New Zealand
Posts: 7
Kimber is on a distinguished road
Default

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
Kimber is offline   Reply With Quote
Old 06-28-2004, 10:52 PM   #5
Votekick
Junior Member
 
Votekick's Avatar
 
Join Date: Nov 2003
Location: USA
Posts: 28
Votekick is on a distinguished road
Send a message via AIM to Votekick Send a message via MSN to Votekick Send a message via Yahoo to Votekick
Arrow

Is it possible using this instead of php or JS from a CSS?
Votekick is offline   Reply With Quote
Old 06-29-2004, 09:47 AM   #6
DCElliott
Administrator
 
DCElliott's Avatar
 
Join Date: Oct 2002
Location: Canada
Posts: 1,196
DCElliott is a splendid one to behold DCElliott is a splendid one to behold DCElliott is a splendid one to behold DCElliott is a splendid one to behold DCElliott is a splendid one to behold DCElliott is a splendid one to behold DCElliott is a splendid one to behold
Default 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!
DCElliott is offline   Reply With Quote
Old 06-29-2004, 05:47 PM   #7
Kimber
Junior Member
 
Join Date: Jun 2004
Location: New Zealand
Posts: 7
Kimber is on a distinguished road
Default

Ooh, thanks heaps, will give it a go
Kimber is offline   Reply With Quote
Old 06-29-2004, 06:05 PM   #8
azlatin2000
Senior Member
 
azlatin2000's Avatar
 
Join Date: Jan 2004
Location: I Forgot
Posts: 459
azlatin2000 is on a distinguished road
Default

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.
azlatin2000 is offline   Reply With Quote
Old 07-04-2004, 11:37 PM   #9
Kimber
Junior Member
 
Join Date: Jun 2004
Location: New Zealand
Posts: 7
Kimber is on a distinguished road
Default

Finally got round to implementing it, and thanks heaps, it worked.
Kimber is offline   Reply With Quote
Old 07-05-2004, 12:24 PM   #10
Free school4u
Probationary
 
Join Date: Jun 2004
Posts: 2
Free school4u is on a distinguished road
Default

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
Free school4u is offline   Reply With Quote
Old 07-06-2004, 02:54 AM   #11
pascal
Senior Member
 
Join Date: Dec 2003
Location: Holland
Posts: 186
pascal is on a distinguished road
Default

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.
pascal is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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.