PDA

View Full Version : Image restore


wap3
06-25-2003, 02:26 PM
Hi guys,

Ok heres the problem.

I have about 5 images on my page which change when you hover the mouse over them. I am using the macromedia swap image code which is this.

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

Now when I mouse over a image it causes it to change, then when I move away it stays at that (as it is suppose to).
Then when I move over another image I need all the other images to restore to there original source before this one is changed.


So basically I need to add something to the function above that says make sure all other images are at their default source before changing the source of this image.

Do you see what I mean ?? :p

Mr J
06-26-2003, 06:04 PM
Something like this maybe?



<script language="JavaScript">
<!--
var Images = new Array("pic1.jpg","pic2.jpg") // list images to preload
var preloadImages=new Array() // preloads images
for (i=0;i<=Images.length-1;i++) {
preloadImages[i]=new Image()
preloadImages[i].src=Images[i]
}

LastID = ""

function m_over(id){
document.getElementById(id).src = "pic2.jpg"
if (LastID != ""){
(LastID != id?document.getElementById(LastID).src = "pic1.jpg":"")
}
LastID = id
}
// -->
</script>

<a href="#null" onMouseOver="m_over('image1')"><img src="pic1.jpg" border="0" id="image1"></a>

<a href="#null" onMouseOver="m_over('image2')"><img src="pic1.jpg" border="0" id="image2"></a>

<a href="#null" onMouseOver="m_over('image3')"><img src="pic1.jpg" border="0" id="image3"></a>

<a href="#null" onMouseOver="m_over('image4')"><img src="pic1.jpg" border="0" id="image4"></a>

<a href="#null" onMouseOver="m_over('image5')"><img src="pic1.jpg" border="0" id="image5"></a>