Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Random Image Script for more than one image slot

Reply
Thread Tools

Random Image Script for more than one image slot

 
 
Linda
Guest
Posts: n/a
 
      01-06-2005
Greetings:

I have found a random image script that I like. It is located here:
http://www.javascriptcity.com/scripts/local/simage3.htm

I'd like to edit this to have 4 different slots for images with a
different set of 5 images for each slot, something like this page:
http://www.uchsc.edu

The script says /* no need to edit past this point (unless you want to
add more image slots) */

Does this mean that you can add more pictures to your array, or, that
you can add more image slots to your web site? Any thoughts on how to
edit this?

Or, do you have another script that can do the same thing? That is,
have random images for 4 different slots on one page? I have searched
a number of web sites and newsgroups and the script located above is
the closest I have found.

BTW; I tried copying and editing the script from the colorado page
http://www.uchsc.edu but couldn't get it to work.

TIA!

Linda

 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      01-06-2005
Linda said:
>
>Greetings:
>
>I have found a random image script that I like. It is located here:
>http://www.javascriptcity.com/scripts/local/simage3.htm


That script does a bad job of generating random numbers.
You can replace "one", "two", "three", and "four" with the id values of your
images, and replace the list of URLs under each one with the URLs that you want
to select from for that image. In this example, they're all the same because I
ran out of demo images. You have add any number of images with any number of
URLs for each one:

<html>
<head>
<script type="text/javascript">
var data = [ "one",
[ "http://www.azphx.com/dhtml/tmp/alpha6464.jpg",
"http://www.azphx.com/dhtml/tmp/beta6464.jpg",
"http://www.azphx.com/dhtml/tmp/gamma6464.jpg",
"http://www.azphx.com/dhtml/tmp/delta6464.jpg"
],
"two",
[ "http://www.azphx.com/dhtml/tmp/alpha6464.jpg",
"http://www.azphx.com/dhtml/tmp/beta6464.jpg",
"http://www.azphx.com/dhtml/tmp/gamma6464.jpg",
"http://www.azphx.com/dhtml/tmp/delta6464.jpg"
],
"three",
[ "http://www.azphx.com/dhtml/tmp/alpha6464.jpg",
"http://www.azphx.com/dhtml/tmp/beta6464.jpg",
"http://www.azphx.com/dhtml/tmp/gamma6464.jpg",
"http://www.azphx.com/dhtml/tmp/delta6464.jpg"
],
"four",
[ "http://www.azphx.com/dhtml/tmp/alpha6464.jpg",
"http://www.azphx.com/dhtml/tmp/beta6464.jpg",
"http://www.azphx.com/dhtml/tmp/gamma6464.jpg",
"http://www.azphx.com/dhtml/tmp/delta6464.jpg"
]
];


function randomImages(d) {
for(var i=0;i<d.length-2;i+=2) {
document.getElementById(d[i]).src=
d[i+1][Math.floor(Math.random()*d[i+1].length)];
}
}
</script>
</head>
<body onload="randomImages(data)">
<h3>One</h3>
<img id="one" src="http://www.azphx.com/dhtml/tmp/alpha6464.jpg">
<h3>Two</h3>
<img id="two" src="http://www.azphx.com/dhtml/tmp/beta6464.jpg">
<h3>Three</h3>
<img id="three" src="http://www.azphx.com/dhtml/tmp/gamma6464.jpg">
<h3>Four</h3>
<img id="Four" src="http://www.azphx.com/dhtml/tmp/delta6464.jpg">
</body>
</html>

 
Reply With Quote
 
 
 
 
Mick White
Guest
Posts: n/a
 
      01-07-2005
Linda wrote:
> Greetings:
>
> I have found a random image script that I like. It is located here:
> http://www.javascriptcity.com/scripts/local/simage3.htm
>
> I'd like to edit this to have 4 different slots for images with a
> different set of 5 images for each slot, something like this page:
> http://www.uchsc.edu
>...


http://www.mickweb.com/javascript/ra...ageOnload.html
function displayRandomImage(imageName,array){
document.images[imageName].src=array[new Date().getTime()%array.length];
}
urls=["images/cs1.jpg","images/cs2.jpg","images/cs3.jpg","images/cs4.jpg"]

<body onload="displayRandomImage('csmember',urls)">
<!-- csmember is the NAME of the image receiving the random changes -->

//<img src="whatever.gif" name="csmember">

Get this working, and with a slight modification we can have as many
random images as you could possibly want.
Mick
 
Reply With Quote
 
Linda
Guest
Posts: n/a
 
      01-07-2005
Dear Lee!

Fabulous! What an elegent script - easy to read and edit! It's works
perfectly, thank you so much!

 
Reply With Quote
 
Linda
Guest
Posts: n/a
 
      01-07-2005
Hi Mick!

Thanks so much for responding. Your script is easy to use, and looks
great. The thing I wanted was more than one
image on the page that could be randomized. Check out what Lee posted.
It works great.

Thanks again for taking the time to respond to my request. I really
appreciate it!

Linda

 
Reply With Quote
 
Mick White
Guest
Posts: n/a
 
      01-07-2005
Linda wrote:

> Hi Mick!
>
> Thanks so much for responding. Your script is easy to use, and looks
> great. The thing I wanted was more than one
> image on the page that could be randomized. Check out what Lee posted.
> It works great.


Indeed it does, but I would use the document.images collection for
greater backwards compatibilty.
Mick

>
> Thanks again for taking the time to respond to my request. I really
> appreciate it!
>
> Linda
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can one declare more than one signal on one line? Merciadri Luca VHDL 4 11-01-2010 02:00 PM
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
random.random(), random not defined!? globalrev Python 4 04-20-2008 08:12 AM
Issue in executing more than one perl script from Single perl script nilesh.sonawane@gmail.com Perl Misc 3 11-01-2007 06:19 PM
XML-Schema: Is there a way to make different type elements(each type has more than one Element) present in random order? Aray XML 1 01-05-2007 08:22 AM



Advertisments