It would had to have been easier to just create local rollovers to accomplish this but, here it is, hopefully you can follow it. There are two examples in the body. The script needs no editing. Works in IE6, NS7.2 and FF1.0.3. I made the links href=# just for testing, set them to whatever pages you like. The name attribute had to be used for the rollover's source in places due to limitations in Mozilla. Unique id's that agree with front and back attributes are required, as shown.
HTML Code:
<html>
<head>
<title>Rollover w/multiple image changes - Demo</title>
<script type="text/javascript">
function init() {
if (!document.getElementById) return
var imgOriginSrc, imgOriginSrcb4, imgOriginSrcaf;
var imgTemp = new Array();
var imgarr = document.getElementsByTagName('img');
for (var i = 0; i < imgarr.length; i++) {
if (imgarr[i].getAttribute('hsrc')) {
imgTemp[i] = new Image();
imgTemp[i].src = imgarr[i].getAttribute('hsrc');
imgarr[i].onmouseover = function() {
imgOriginSrc = this.getAttribute('src');
imgOriginSrcb4 = document.getElementById(this.getAttribute('front')).src;
imgOriginSrcaf = document.getElementById(this.getAttribute('back')).src;
document.getElementById(this.getAttribute('front')).src=document.getElementById(this.getAttribute('front')).name
document.getElementById(this.getAttribute('back')).src=document.getElementById(this.getAttribute('back')).name
this.setAttribute('src',this.getAttribute('hsrc'))
}
imgarr[i].onmouseout = function() {
this.setAttribute('src',imgOriginSrc)
document.getElementById(this.getAttribute('front')).src=imgOriginSrcb4
document.getElementById(this.getAttribute('back')).src=imgOriginSrcaf
}
}
}
}
onload=init;
</script>
</head>
<body><img id="b41" border="0" src="photo1.jpg" name="photo2.jpg" width="140" height="225" alt="">
<a href="#">
<img border="0" front="b41" back="af1" src="thumb1.jpg" hsrc="thumb2.jpg" width="50" height="50" alt="Click Here Info"></a>
<img border="0" id="af1" src="photo3.jpg" name="photo4.jpg" width="140" height="225" alt=""><br>
<img border="0" id="b42" src="photo5.jpg" name="photo6.jpg" width="140" height="225" alt="">
<a href="#">
<img border="0" front="b42" back="af2" src="thumb3.jpg" hsrc="thumb4.jpg" width="50" height="50" alt="Click Here Info"></a>
<img border="0" id="af2" src="photo7.jpg" name="photo8.jpg" width="140" height="225" alt=""><br>
</body>
</html>
Bookmarks