...

View Full Version : random image script



JpDm
01-15-2004, 09:06 PM
hi :)

was just wondering if anyone knew a script for a random image generator..i cant seem to find one, and i dont know the script :x

ex. i have 3 pictures
when i go to my site... u'd see one of the pictures in the middle, but when u refresh/reload the page.. a different picture would be there.. and yea :D

was just wondering if anyone knew a script for that, and if you could please show me if you did :(

thx in advance ;)

fredmv
01-15-2004, 09:13 PM
<script type="text/javascript">
//<![CDATA[
onload = function()
{
var images =
[
'foo1.png',
'foo2.png',
'foo3.png'
];

document.images[0].src = images[Math.floor(Math.random()*images.length)];
}
//]]>
</script>
<img src="blank.png" alt="" />

Garadon
01-15-2004, 10:15 PM
if u plan on calling ur pictures the same with a simple number increaser the array from above reply becomes redundant: u could then just write.
And this is only my opinion but refering to a specific image in the documents image array by its number is something one should stay away from since it hampers development of at site, use id locating or some other method. That is only my opinion.


onload = function()
{
var pics=3;
document.getElementById('pic').src ="foo"+Math.floor(Math.random()*pics);
}


Image:
<img src="blank.png" alt="" id="pic" />


I got a quenstion I seen many use this <![CDATA[
but what does it do?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum