PDA


View Full Version : Random Image


wattie
06-02-2005, 09:28 PM
I wanted a module for my home page which would show a random image from a selection of my own. As I couldnt find one which suited my purpose, I read up on what to do, canibalised bits of different scripts (so appologies if you recognise something of yours here!) and came up with this:
<table align="center" border="0" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" class="tborder" width="100%">
<tr>
<td class="tcat"><span class="smallfont"><b>$vba_options[portal_blockbullet] Northenders</b></span></td>
</tr>
<tr>
<td class="$getbgrow" width="100%">

<!-- Begin custom code -->
<script language="Javascript"><!--

function image() {
};

image = new image();
number = 0;

// imageArray
image[number++] = "<img src='picture1.jpg' border='1'>"
image[number++] = "<img src='picture2.jpg' border='1'>"
// Carry on adding images - as many as you want

increment = Math.floor(Math.random() * number);

document.write(image[increment]);

//-->
</script>
<!-- End custom code -->

</td>
</tr>
</table>
<br />All you do is make a template with the above code in it, put the images in your main directory, make a new module using the template and simply change picture1.jpg etc to the filename of your picture. Add as many as you like!
As I said, this is my first attempt at putting this together and was amazed when it actually worked!
Enjoy!

mholtum
06-02-2005, 10:06 PM
Not bad, nice work.

tomshawk
06-02-2005, 10:30 PM
question

If you dont want the images riddling your root directory

could you change this portion

image[number++] = "<img src='picture1.jpg' border='1'>"

with this

image[number++] = "<img src='images/random/picture1.jpg' border='1'>"

Just to keep things organized.

FightRice
06-02-2005, 10:50 PM
Yes you should be able to as long as it still points to your images

Thats the script i use to rotate banners on my site though :) Works like a charm if anyones thinking of using it

mholtum
06-03-2005, 01:18 AM
Can you add a time delay so they rotate without changing the page?

wattie
06-03-2005, 04:53 AM
Can you add a time delay so they rotate without changing the page?
Sorry - this has been a steep learning curve for me and I have no idea how to do that!

mholtum
06-03-2005, 10:19 AM
Purhaps I will work on it later.