View Full Version : Need random image script to randomize multiple times per page.
HELLSS
09-04-2002, 11:17 AM
http://hellssite.customc.net in the main frame on that first page i've got those background images randomized... only problem is I don't want them all turning into the same image but randomizing for each one. I could make seperate random image scripts for each image spot but in some cases I may be using 5+ of those images per-page so that's a really un needed thing to do I think.
Does anyone know how to make it randomize how I desire? Here is the code involved:
<script>
var imagenumber = 5 ;
var randomnumber = Math.random() ;
var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;
images = new Array
images[1] = "http://customc.net/hosted/hellssite/pics/terrain/terrain1.gif"
images[2] = "http://customc.net/hosted/hellssite/pics/terrain/terrain2.gif" <-- up to terrain12.gif
var image = images[rand1]
</script>
____________________code image shows up at___________________
<script>
document.write('<IMG SRC="' + image + '">')
</script>
thanks for any help. even if you can point me to a script which does this that will be ok.
kansel
09-04-2002, 04:22 PM
This thread: http://www.codingforums.com/showthread.php?s=&threadid=4614
is about picking unique random numbers. All you need to do is supply a list of numbers to choose from.
Take a look at the htm file within the zip file.
The script is set up for 3 events.
At the lines:
images[images.length] = "bigpic1.gif"
and within the img tags
Change to your images.
events=3 is the number of events
The following statements and img tags should always correspond
document.pic1.src=images[pic[0]] // event 1
document.pic2.src=images[pic[1]] // event 2
document.pic3.src=images[pic[2]] // event 3
<img src="bigpic1.gif" name="pic1" width=100 height=100> <!-- event 1 -->
<img src="bigpic1.gif" name="pic2" width=100 height=100> <!-- event 2 -->
<img src="bigpic1.gif" name="pic3" width=100 height=100> <!-- event 3 -->
More events can be added providing you take into account the index number must be sequential.
IE:
[pic[3]], [pic[4]] for the statements
and
pic3, pic 4 for the image names
and to change events=3 to the number that you have
etc, etc.
Any queries just ask
:thumbsup:
HELLSS
09-05-2002, 01:02 AM
other than taking out the set timout part of the script so it didnt change images all the time it works. But there's one thing missing from it which I want in the script, not placing the same image more than once per page reload. so there won't be two of image1 on the page and so on.
the script the other guy linked to does this... but I don't know how to make that script able to place images anywhere on a page and not right beside eachother... I tried a few things but nothing worked. Here is the script which i'm referring to:
<script language="JavaScript">
// Unique Random Numbers Picker
// -Picks a number of unique random numbers from an array
// (c) 2002 Premshree Pillai
// http://www.qiksearch.com, http://javascript.qik.cjb.net
// E-mail : qiksearch@rediffmail.com
var numArr = new Array("1","2","3","4","5","6","7","8","9","10","11","12"); // Add elements here
var pickArr = new Array(); // The array that will be formed
var count=0;
var doFlag=false;
var iterations=0;
function pickNums(nums)
{
iterations+=1;
var currNum = Math.round((numArr.length-1)*Math.random());
if(count!=0)
{
for(var i=0; i<pickArr.length; i++)
{
if(numArr[currNum]==pickArr[i])
{
doFlag=true;
break;
}
}
}
if(!doFlag)
{
pickArr[count]=numArr[currNum];
//document.write(numArr[currNum] + '<font color="#808080">|</font> ');
document.write('<img name=cc1 src=pics/' + numArr[currNum] + '.gif border=0>');
count+=1;
}
if(iterations<(numArr.length*3)) // Compare for max iterations you want
{
if((count<nums))
{
pickNums(2);
}
}
else
{
location.reload();
}
}
pickNums(2);
</script>
So a hybrid of the script you provided and the script the other guy linked to is required for my appetitie :o
I'm a fairly big novice to javascripts so I have no clue how to accomplish that myself.
Have a play with the attached file.
Don't forget to change the image source to your own
;)
HELLSS
09-05-2002, 07:17 PM
*bows to the almighty*
:) :o ;) :cool: :thumbsup:
thank you thank you thank you thhhaaaannnkkk you!
i'll place a little credit text to you in the script to thank you even further hehe.
Thank you
Credit should read
Apachejeff
MY scripting name :D
:thumbsup: :thumbsup: :thumbsup:
HELLSS
09-06-2002, 11:07 AM
mm'kay i'll be sure to change your name to that the next time I go around editing all my pages... which i'm sure will be very soon.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.