You can put the image tags in tables or wherever you like in your markup. Here is a commented script demo that will show you how to do the rest:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var pic_sets = {
preload:true, // set to true or false
// first image in each set should be the corresponding image tag's actual src image.
// each set may have as many images as you like, other sets may be added.
pic_set_1:['some.gif', 'another.gif', 'bob.gif'],
pic_set_2:['mary.gif', 'sid.gif', 'susie.gif', 'alice.gif'],
///////////////// Stop Editing /////////////////
change:function(el){
var a=pic_sets[el.id];
for (var re, pnum = 0, i = a.length - 1; i > -1; --i){
re = new RegExp(a[i]);
if(re.test(el.src))
pnum = i;
}
pnum = pnum < a.length - 1? pnum + 1 : 0;
el.src = a[pnum];
}
};
(function(){
if (!pic_sets.preload)
return;
var im = [];
for (var p in pic_sets)
if(/pic_set/.test(p))
for (var i = pic_sets[p].length - 1; i > 0; --i){
im[im.length] = new Image();
im[im.length - 1].src = pic_sets[p][i];
}
})();
</script>
</head>
<body>
<img id="pic_set_1" src="some.gif" onclick="pic_sets.change(this);">
<img id="pic_set_2" src="mary.gif" onclick="pic_sets.change(this);">
</body>
</html>
Questions? Just ask.
Bookmarks