It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Random Image script with default image shown first

Random Image script with default image shown first

Postby dellfred on Wed Feb 16, 2011 5:52 am

Here's what I usually use and have been using for years and it works great, just not for this particular purpose. I don't have a clue when it comes to javascript.

Code: Select all
<noscript><img src="no_script_quote.gif" width="406" height="94"/></noscript><script language="javascript">

var delay=6000
var curindex=0

var images=new Array()

    images[0]="quote1.gif"
    images[1]="quote2.gif"
    images[2]="quote3.gif"
    images[3]="quote4.gif"
    images[4]="quote5.gif"

var preload=new Array()

for (n=0;n<images.length;n++)
{
    preload[n]=new Image()
    preload[n].src=images[n]
}

document.write('<img name="defaultimage" src="'+images[Math.floor(Math.random()*(images.length))]+'">')

function rotateimage()
{

if (curindex==(tempindex=Math.floor(Math.random()*(images.length)))){
curindex=curindex==0? 1 : curindex-1
}
else
curindex=tempindex

    document.images.defaultimage.src=images[curindex]
}

setInterval("rotateimage()",delay)
</script>


But, now I want to be able to set a default picture to be shown first and have the random pics appear next. I also don't want the default pic to show up again in the random array. So basically, every time the page was first visited, or refreshed it would show the default picture then move into the random pics.

Is there anyway to modify the code that I'm using to accomplish this? Or... Any help would be appreciated.

Thanks,
Dell
dellfred
 
Posts: 1
Joined: Wed Feb 16, 2011 5:46 am

Who is online

Users browsing this forum: No registered users and 11 guests