PDA

View Full Version : Need image swap......


Dr. Web
03-20-2001, 05:39 PM
added to a DHTML menu. When I tried it I crashed the whole menu system! Here is a link to the bare bones menu script. I have replaced the text links with pictures, and would like to add onMouseover functionality. Actually, I don't ...the client does! heres the original menu....

http://www.bratta.com/dhtml/scripts.asp

under scripts, its called...foldout menu


[Edited by Dr. Web on 03-20-2001 at 05:42 PM]

Ian
03-20-2001, 07:55 PM
Hi Doc,
This SHOULD work, but I havent tested it.
First define your images and preload them. (in brackets is the image size)

<script language="javascript1.1">
<!--

a1=new Image(20,20)
a1.src="off.gif"
a2=new Image(20,20)
a2.src="on.gif"
//-->
</script>

next create a function to make them swap.

<script>
<!--
function swap(imagename,objectsrc){
if (document.images)
document.images[imagename].src=eval(objectsrc+".src")
}
//-->
</script>

lastly add your link like so:

<div id="divSub1" class="clSub">
&nbsp;<a href="#" class="clSubb" onmouseover="swap('swapfirst','a2')"
onmouseout="swap('swapfirst','a1')"><img src="off.gif" name="swapfirst" border=0 width=20 height=20></a><br>

you may have to change function names, image names (a1, a2, etc) to avoid any conflicts within the current sripts functions, but it should work.