Jump to content

I need a random images script


TheBlueDragon

Recommended Posts

Hi,

I wonder if anyone can help me. I need a random image script for a website, but I need one that will allow me to have 4 areas on 1 webpage which all show different radom images

 

[images 1, 2, 3, 4]

 

[images 5, 6, 7, 8]

 

[images 9 10, 11, 12]

 

[images 13, 14, 15, 16]

 

If you get what I mean

________

Babe Video

Link to comment
Share on other sites

How about using java?

 

This in a .js file...

 

var imageArray = new Array();

imageArray[0] = new Image();
imageArray[0].src = "/images/myimage1.jpg";
imageArray[1]  = new Image();
imageArray[1].src = "/images/myimage2.jpg";

var imageCounter = 0;

function rotateImages()
{
   var myImage = document.getElementById("myimage");
   myImage.src = imageArray[imageCounter++].src;

   if( imageCounter == imageArray.length)
   {
      imageCounter = 0;
   }

   setTimeout("rotateImages()", 10000);
}

 

This in the <head>...

 

<script type="text/javascript" src="myimage.js"></script>

 

& then this...

 

<img id="myimage">

 

where you want it...

 

I think that's all you need?

Link to comment
Share on other sites

Link to comment
Share on other sites

Er... :confused:

 

I seem to remember there was something daft that stopped it working...

 

"<img id=\"myimage\" border=\"0\" width=\"732\" height=\"210\" />";

 

The original (working) use has the image width/height specified as above...

 

other than that try on hotscripts, there was something very similar there, but with better documentation than me going er... :hihi:

Link to comment
Share on other sites

I have found a php based solution, so providing your server supports it, it'll work even on java-disabled machines, and will make for cleaner source code.

 

http://alistapart.com/articles/betterrotator/

 

It works for me (I use it to change the image on my homepage...), and allows for placement of images anywhere on the page using simple

<?php include.... ?>

tags. You also don't need to know how to use php to get it to work!

 

PM me if you have any difficulties or questions :thumbsup:

Link to comment
Share on other sites

php

$dh = opendir(".");

while (false !== ($file = readdir($dh)))

{

if (preg_match('/\.jpg$/i', $file) and $file != "avatar.jpg")

{

$filelist[] = $file;

}

}

 

srand((double)microtime()*1000000);

$picnum = rand(0, sizeof($filelist) - 1);

 

header("Location: " . $filelist[$picnum]);

 

closedir($dh);

?

Link to comment
Share on other sites

Are you trying to have an image that changes each time the person visits the page or one that changes periodically while the user is viewing the page?

The script that Steev posted will do the latter and won't work for multiple images without some modification (and won't do anything without an onload="rotateImages()" in your body tag, which is probably why you aren't seeing any results). If this is the effect you are going for however, Javascript is the way to go.

If you are going for the former then I'd say a server side script is preferable but it's still doable in Javascript if that's not an option. If you've php available then you're already sorted. :thumbsup:

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.