TheBlueDragon Posted September 21, 2006 Share Posted September 21, 2006 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 More sharing options...
Stuff Posted September 21, 2006 Share Posted September 21, 2006 Which technology are you using? Client-side or server-side? If client-side, try looking for a Javascript on: The Javascript Source Link to comment Share on other sites More sharing options...
steev Posted September 21, 2006 Share Posted September 21, 2006 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 More sharing options...
TheBlueDragon Posted September 21, 2006 Author Share Posted September 21, 2006 I cant seem to get that to work, Click here to view the page Click here to view the script and these are the first 4image I want to use for the image on the top right of the webpage http://www.ciarts.co.uk/img/marginimages/lantern1.jpg http://www.ciarts.co.uk/img/marginimages/lantern2.jpg http://www.ciarts.co.uk/img/marginimages/lantern3.jpg http://www.ciarts.co.uk/img/marginimages/lantern4.jpg ________ Low Cost Vaporizer Link to comment Share on other sites More sharing options...
steev Posted September 21, 2006 Share Posted September 21, 2006 Er... 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... Link to comment Share on other sites More sharing options...
Stuff Posted September 21, 2006 Share Posted September 21, 2006 How about using java? That's Javascript, not Java Link to comment Share on other sites More sharing options...
steev Posted September 21, 2006 Share Posted September 21, 2006 That's Javascript, not Java Tch, whatevvuh As you can tell by my last post, I know neither Link to comment Share on other sites More sharing options...
mr chris Posted September 21, 2006 Share Posted September 21, 2006 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 Link to comment Share on other sites More sharing options...
21steve Posted September 21, 2006 Share Posted September 21, 2006 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 More sharing options...
Nazo Posted September 21, 2006 Share Posted September 21, 2006 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.