 |
 |
random images
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2001
Location: Portland, OR USA
Status:
Offline
|
|
I have 3 sets of two images that need to be randomly selected on refresh. The sets of images are right on top of each other in a table. Any suggestions?
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: May 2001
Location: Nottingham, UK
Status:
Offline
|
|
is your website sitting on a unix or nt machine?
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status:
Offline
|
|
Originally posted by jonathan stick:
<STRONG>I have 3 sets of two images that need to be randomly selected on refresh. The sets of images are right on top of each other in a table. Any suggestions?</STRONG>
Sure - a document.write which uses a random number generator.
Say you had image1a.jpg, image1b.jpg, image2a.jpg, image2jpg, etc...
A line like this could work a treat:
<td>
<script language="javascript" type="text/javascript"><!--
document.writeln('<img alt="Pic1" src="image"'+(Math.round(Math.random()*3))+'a.jpg width="50" height="50"><img alt="Pic1" src="image"'+(Math.round(Math.random()*3))+'b.jpg width="50" height="50">');
// --></script>
</td>
This is code I've just put together to illustrate a point - I've not used the Math functions for a bit, so it might not work as expected. I just wanted to show how you could go about it easily. A reference book will fill in the necessary detail. :-)
Hope this helps
|
|
Computer thez nohhh...
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2001
Status:
Offline
|
|
Originally posted by jonathan stick:
<STRONG>I have 3 sets of two images that need to be randomly selected on refresh. The sets of images are right on top of each other in a table. Any suggestions?</STRONG>
This has been covered before.
Use client-side javascript if you really mean random and your audience will be using browsers capable of javascript and displaying images.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2001
Location: Portland, OR USA
Status:
Offline
|
|
I understand that it's javascript I want, I just need a more complex script than anyone seems to be offering. The scripts I've used are fine, totally fine, for one image to be displayed at a time, but I have TWO images and they are in sets, so they need to be randomly selected in sets.
i.e.
Let's say I have one image that says "HELLO" and another placed directly below it that says "CUSTOMERS", now I want to be able to have random greetings load in on refresh. So you'll get something like "HELLO" "CUSTOMERS", "GREETINGS" "FRIENDS", "GOOD DAY" "SIRS" everytime you refresh. Get it? TWO images that have to stay together, or they won't line up.
Does anyone know how to do that client-side?
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2001
Location: Portland, OR USA
Status:
Offline
|
|
Oh yea.
It's a unix machine.
I'd like to do this with a simple javascript if possible.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2001
Location: Portland, OR USA
Status:
Offline
|
|
Okay, I got it.
If anyone needs this in the future, here is an easy way to do it:
<script language="javascript">
images_top = new Array(2);
images_bottom = new Array(2);
images_top[0] = 'gfx/spash_science_logo_bar.jpg'
images_bottom[0] = 'gfx/splash_science_banner.jpg'
images_top[1] = 'gfx/spash_conversion_logo_bar.jpg'
images_bottom[1] = 'gfx/splash_conversion_banner.jpg'
images_top[2] = 'gfx/spash_dict_logo_bar.jpg'
images_bottom[2] = 'gfx/splash_dict_banner.jpg'
index = Math.floor(Math.random() * images_top.length);
document.write("<IMG SRC="+images_top[index]+" width=571 height=99>");
document.write("<IMG SRC="+images_bottom[index]+" width=571 height=88>");
</script>
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Jan 2002
Location: Apex, NC
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|