Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Random graphic with a twist - help please

    I would like to have my header graphic change randomly, without ssi. Doing a search of the forums, I found this post:
    Need help showing a random image

    That script, shown below, is exactly what I need BUT, I need to modify it and I am not sure how. My header graphic is quite large and I want to slice it up into several peices. How can I load a random header when the header is broken into several smaller graphics - I need the 4 peices to all match!


    Code:
    <script language="JavaScript" type="text/javascript">
    // This script was supplied free by Hypergurl
    // http://www.h y p e r g u r l .com   remove the spaces
    <!--
        // JavaScript to interpolate random images into a page.
        var ic = 6;     // Number of alternative images
        var xoxo = new Array(ic);  // Array to hold filenames
            
    xoxo[0] = "http://www.yoursite.com/graphic1.gif";
    xoxo[1] = "http://www.yoursite.com/graphic2.gif";
    xoxo[2] = "http://www.yoursite.com/graphic3.gif";
    xoxo[3] = "http://www.yoursite.com/graphic4.gif";
    xoxo[4] = "http://www.yoursite.com/graphic5.gif";
    xoxo[5] = "http://www.yoursite.com/graphic6.gif";
    
    function pickRandom(range) {
    if (Math.random)
    return Math.round(Math.random() * (range-1));
    else {
    var now = new Date();
    return (now.getTime() / 1000) % range;
    }
    }
    // Write out an IMG tag, using a randomly-chosen image name.
    var choice = pickRandom(ic);
    // -->
    </script>

    Code:
    <SCRIPT LANGUAGE="JavaScript">document.writeln('<TD'+'><IMG SRC="'+xoxo[choice]+'" HEIGHT=184 WIDTH=120 BORDER=0 ><'+'/TD>');</SCRIPT>
    Any help would be appreciated,

    cbouchar

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,505
    Thanks
    3
    Thanked 501 Times in 488 Posts
    PHP Code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd"
    >

    <
    html>

    <
    head>
      <
    title></title>
    <
    script language="JavaScript" type="text/javascript">
    // by Vic Phillips [url]http://www.vicsjavascripts.org.uk[/url]


    var ImgPath='http://www.vicsjavascripts.org.uk/StdImages/';

    var 
    ImgAry = new Array();  // Array to hold filenames
    ImgAry[0] = ['Zero.gif','One.gif','Two.gif'];
    ImgAry[1] = ['One.gif','Two.gif','Three.gif'];
    ImgAry[2] = ['Two.gif','Three.gif','Four.gif'];
    ImgAry[3] = ['Three.gif','Four.gif','Five.gif'];

    set=Math.floor(Math.random()*ImgAry.length)

    function 
    LoadDisplay(){
     for (
    i=0;i<3;i++){
      
    document.getElementById('MyImg'+i).src=ImgPath+ImgAry[set][i];
     }
    }

    // -->
    </script>
    </head>

    <body onload="LoadDisplay();" >


    <img id="MyImg0" src="Blank.gif" width="50" height="50"><img id="MyImg1" src="Blank.gif" width="50" height="50"><img id="MyImg2" src="Blank.gif" width="50" height="50">
    </body>

    </html> 
    Last edited by vwphillips; 03-26-2005 at 02:27 PM.


  •  

    Posting Permissions

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