View Full Version : Basic coding question: random images
photoguy6405
17th of January 2010 (Sun), 02:24
Putting together new website. As much as I really dislike flash, I was thinking of a slideshow on the home page with about 5-6 images. No interaction... that would be in the galleries... just some variety.
I've decided against the slideshow. What I'd like to do instead would be to have 5-6 chosen images appear at random whenever somebody goes to the home page. It won't change or do anything once they get there, but when they go back the image will be different, and will be different at random every time they visit.
I know I've seen this before a long time ago, and wonder if there's a simple code to display images at random like this.
I'm venturing into CSS with this website, if that makes a difference. Thanks.
pickupman92
17th of January 2010 (Sun), 02:29
Do you want to do this with pure CSS or do you care about javascript?
here's some info on pure CSS
http://www.sitepoint.com/forums/showthread.php?threadid=208047#
hope this helps.
Faolan
17th of January 2010 (Sun), 05:15
Look at the various JQuery type galleries around, some do random images and are a blend of CSS/JavaScript/XHTML....
http://www.davidvanvickle.com/go.php?p=jquery-slideshow
SwitchBlade
17th of January 2010 (Sun), 07:24
Can be done very simply in plain old javascript.
Dinoman
17th of January 2010 (Sun), 09:49
:) You can try this, I've used it before without any trouble (later decided to do something else), easy to modify if you need to. Its just a PHP script that pulls files from a folder so when you want to add more pictures you can just upload them to the folder.
http://www.marcofolio.net/webdesign/php_random_image_rotation.html
photoguy6405
20th of January 2010 (Wed), 01:27
I ended up going with this. Simple and works nicely, though I wish it had something that would avoid repeats. The repeats aren't too common, but do happen as it's a true random.
http://www.java-scripts.net/javascripts/Random-Image-Script.phtml
Hikin Mike
20th of January 2010 (Wed), 02:05
I ended up going with this. Simple and works nicely, though I wish it had something that would avoid repeats. The repeats aren't too common, but do happen as it's a true random.
http://www.java-scripts.net/javascripts/Random-Image-Script.phtml
Just know that if somebody has Java disabled, they won't see your images. ;)
photoguy6405
20th of January 2010 (Wed), 07:02
Just know that if somebody has Java disabled, they won't see your images. ;)
Yeah, I read that somewhere.
I may "upgrade" to something else still, but for the moment it'll do until I finish the other pages, photos, etc.
Hikin Mike
20th of January 2010 (Wed), 12:50
Yeah, I read that somewhere.
I may "upgrade" to something else still, but for the moment it'll do until I finish the other pages, photos, etc.
I had the same type of random script a few years ago. I was able to have a 'static' photo, so if Javascript was disabled you can see one image. Unfortunately I don't have the 'code'. :rolleyes:
Todd Lambert
20th of January 2010 (Wed), 13:02
You can easily add a noscript tag in there along with your javascript, that will add a default image, if the user has javascript disabled. (btw, the days of people having javascript disabled are long gone in my opinion - it's everywhere nowadays, so without javascript, the web world is a rather dull, non-functional place)
However, that said, I wouldn't use something like javascript for this. I'd use a server side language instead - either php or asp, depending on your server and needs.
The link that Dinoman indicated, or something like it, would be the route I'd go (I actually have used this same method before several times)
Good luck.
8-)
vBulletin® v3.6.12, Copyright ©2000-2012, Jelsoft Enterprises Ltd.