Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2010
    Location
    Battle Ground, WA
    Posts
    273
    Plugin Contributions
    1

    Default Change background on refresh

    I'd like to change the background on every refresh...
    I looked this up on google and this is what I came up with:
    (My problem is, I did all this but it didnt work! )

    Add this to your php file:

    Code:
    <?php 
    $imagearray=file('background.inc.php'); 
    $imagenum=rand(0,count($imagearray)-1); 
    ?>
    Add this to your css:

    Code:
    div.container { 
    padding : 95px 20px 20px 161px; 
    background : url(<?php echo $imagearray[$imagenum];?>) #FFFFFF repeat; 
    margin-top: nem 
    }
    And make a new file called "background.inc.php" and inside it put:

    Code:
    images/image1.jpg
    images/image2.jpg
    images/image3.jpg
    etc, no blank lines, no quotes, no spaces, no semi-colons

    My problem is, I did all this but it didnt work!
    Last edited by dddmx3; 24 Feb 2011 at 06:11 AM.

  2. #2
    Join Date
    Jul 2010
    Location
    Battle Ground, WA
    Posts
    273
    Plugin Contributions
    1

    Default Re: Change background on refresh

    Or if I would like for it to change daily, where could I put this code?

    Code:
        <script>
    
          function dailyBackground(node,images)
          {
            node.style.backgroundImage = "url(\""+images[Math.floor(new Date().getTime()/86400000)%images.length]+"\")";
          }
    
        </script>
    
      </head>
     
      <body>
     
        <h1>Daily Background Image</h1>
       
        <script>
       
          var imgArray = new Array();
          imgArray[0] = "images/image1.jpg";
          imgArray[1] = "images/image2.jpg";
          imgArray[2] = "images/image3.jpg";
    
          dailyBackground(document.body,imgArray);
         
        </script>

  3. #3
    Join Date
    Jul 2010
    Location
    Battle Ground, WA
    Posts
    273
    Plugin Contributions
    1

    Default Re: Change background on refresh

    Figured it out.
    I put this code into /includes/templates/MY_TEMPLATE/tpl_index_default.php right before the line: <div class="centerColumn" id="indexDefault">

    Code:
    <script>
    
          function dailyBackground(node,images)
          {
            node.style.backgroundImage = "url(\""+images[Math.floor(new Date().getTime()/86400000)%images.length]+"\")";
          }
    
        </script>  
        <script>
       
          var imgArray = new Array();
          imgArray[0] = "includes/templates/MY_TEMPLATE/images/bg1.jpg";
          imgArray[1] = "includes/templates/MY_TEMPLATE/images/bg2.jpg";
          imgArray[2] = "includes/templates/MY_TEMPLATE/images/bg3.jpg";
    	  imgArray[3] = "includes/templates/MY_TEMPLATE/images/bg4.jpg";
    	  imgArray[4] = "includes/templates/MY_TEMPLATE/images/bg5.jpg";
    	  imgArray[5] = "includes/templates/MY_TEMPLATE/images/bg6.jpg";
    	  imgArray[6] = "includes/templates/MY_TEMPLATE/images/bg7.jpg";
    	  imgArray[6] = "includes/templates/MY_TEMPLATE/images/bg8.jpg";
    
          dailyBackground(document.body,imgArray);
         
        </script>

 

 

Similar Threads

  1. v150 How to randomly rotate header background image on refresh?
    By scott_ease in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 2 Jul 2015, 01:07 PM
  2. Background Image Rotation on Refresh
    By mishutkadesign in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 12 Mar 2010, 05:06 AM
  3. Page Refresh on Language Change
    By mrrcomp in forum Addon Language Packs
    Replies: 8
    Last Post: 23 Feb 2009, 08:54 AM
  4. How to Change Background Colour to Background image
    By ittybittykitty in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 9 Aug 2008, 04:36 PM
  5. Main page screwing up from refresh to refresh ...
    By Giftbox in forum General Questions
    Replies: 1
    Last Post: 20 Nov 2007, 12:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg