
Originally Posted by
auntnini
Still wish I could comprehend your first version using CSS.
I don't know what you mean there.
I've actually re-done the script using DOM. Here's the code and I hope you like it 
The script is really easy to follow
The script takes the following layout:
[Image Path,Caption]
eg.
Code:
["critters/rembrantGirlBroom.jpg","alttext"],
Let me know if you have any problems.
HTML Code:
HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Random Images with Captions, IDs etc.</title>
<script type="text/javascript">
/*******************
Random Image Sets by Peter Nguyen
Dynamic Drive Forums User: tech_support
This notice must stay intact for legal use
********************/
//Slide Set Images
var slideSets = new Array();
slideSets[0] = [
["critters/rembrantGirlBroom.jpg","alttext"],
["floral/cezanne.chrysanthemums.jpg","alttext"],
["floral/vanGogh12sunflowers.jpg","alttext"],
["floral/vanGoghSunflowers.jpg","alttext"],
["scenes/vanGogh.gif","alttext"],
["scenes/cole.jpg","alttext"]
];
slideSets[1] = [
["chanit/things/AnemonaesWC.jpg","alttext"],
["chanit/things/floralApples.jpg","alttext"],
["chanit/things/floralRecycle.jpg","alttext"],
["chanit/things/floristDozen.jpg","alttext"],
["chanit/things/moreAnemonaes.jpg","alttext"],
["chanit/things/Neighbors.jpg","alttext"]
];
slideSets[2] = [
["critters/rembrantGirlBroom.jpg","alttext"],
["floral/cezanne.chrysanthemums.jpg","alttext"],
["floral/vanGogh12sunflowers.jpg","alttext"],
["floral/vanGoghSunflowers.jpg","alttext"],
["scenes/vanGogh.gif","alttext"],
["scenes/cole.jpg","alttext"]
];
/* Generate a random number, do it again if the number has already been chosen */
var oldr;
function randomizer(maxnum) {
//maxnum++
var r = Math.floor(Math.random() * maxnum)
if (r == oldr) {
return randomizer(maxnum)
}
else {
oldr = r;
return r;
}
}
/*Display random image sets */
function randomImgSets(arrayImgSetPaths,setsCount,divDisplay) {
for (i=0; i < setsCount; i++) {
var r = randomizer(arrayImgSetPaths.length)
for (s=0; s < arrayImgSetPaths[r].length; s++) {
var id = document.getElementById(divDisplay)
if (document.createElement) {
var e = document.createElement("img")
e.setAttribute("src", arrayImgSetPaths[r][s][0]+"?r="+r)
e.setAttribute("alt", arrayImgSetPaths[r][s][1])
e.setAttribute("id", arrayImgSetPaths[r][s][2])
id.appendChild(e)
}
else {
var content = '<img src="'+arrayImgSetPaths[r][s]+'" alt="Random Set Number: '+r+' Image Number: '+s+'"> <br>'
id.innerHTML += content;
}
}
}
}
window.onload = function() {
randomImgSets(slideSets, 1, "sliders")
}
</script>
</head>
<body>
<div id="sliders"></div>
</body>
</html>
Bookmarks