PDA

View Full Version : Background Image Slideshow - Random?



freezerburn26
10-05-2004, 03:45 AM
I was wondering how you would go about doing the Background image slideshow but instead of just cycling through the images you go through them randomly. Thanks. Background Image Slideshow (http://www.dynamicdrive.com/dynamicindex14/bgslide.htm)

cr3ative
10-05-2004, 02:18 PM
Use this code I've made for you instead, place in BODY section as usual:

It's important to note the instructions on this line:
// The final number (default=3) of the next line must be equal to the number of images present.
inc=Math.floor(Math.random() * 3)

The code:


<style>
body{
/*Remove below line to make bgimage NOT fixed*/
background-attachment:fixed;
background-repeat: no-repeat;
/*Use center center in place of 300 200 to center bg image*/
background-position: 300 200;
}
</style>

<script language="JavaScript1.2">

//Background Image Slideshow- Dynamic Drive (www.dynamicdrive.com)
//For full source code, 100's more DHTML scripts, and TOS,
//visit http://www.dynamicdrive.com
//modified by cr3ative for random backgrounds

//Specify background images to slide
var bgslides=new Array()
bgslides[0]="bgslide.jpg"
bgslides[1]="bgslide2.jpg"
bgslides[2]="bgslide3.jpg"

//Specify interval between slide (in miliseconds)
var speed=3000

//preload images
var processed=new Array()
for (i=0;i<bgslides.length;i++){
processed[i]=new Image()
processed[i].src=bgslides[i]
}

var inc=-1

function slideback(){
if (inc<bgslides.length-1)

// The final number (default=3) of the next line must be equal to the number of images present.
inc=Math.floor(Math.random() * 3)

else
inc=0
document.body.background=processed[inc].src
}

if (document.all||document.getElementById)
window.onload=new Function('setInterval("slideback()",speed)')

</script>


Regards
cr3ative

cheekymassey
11-18-2004, 01:17 PM
Hi there,

Would anyone possibly be able to take a look at randomizing the photos on this script?:

http://www.dynamicdrive.com/dynamicindex14/image4.htm

I would have tried it myself, however it's a bit different to the background images script, in that each thumbnail image also has a hyperlink to the main image.

Thanks.