Click to See Complete Forum and Search --> : Please help with a rollover
My problem is that I am trying to use a image flip script for the menu on a page. But somewhere I have made a mistake because no matter which image I rollover with my mouse the same image changes. Please help. the address of the page is http://www.angelfire.com/art2/aimi/index.html I am not sure where I made the mistake. But please help me. I have attached the source code in a text file.
ShrineDesigns
12-15-2002, 07:33 PM
this should do it
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
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];}
}
//-->
</script>
</head>
<body>
<div align="center">
<p><a href="index.html" onMouseOver="MM_swapImage('home','','home.jpg',0)" onMouseOut="MM_swapImgRestore()"><img name="home" src="home.gif" border="0"></a></p>
<p><a href="aboutus.html" onMouseOver="MM_swapImage('about','','aboutus2.jpg',0)" onMouseOut="MM_swapImgRestore()"><img name="about" src="aboutus.gif" border="0"></a></p>
</div>
</body>
</html>
The code that ShrineDesigns gave you is from Dreamweaver. It works well, but I thought I'd give you a different way to do it.
This is to preload you images.
<SCRIPT LANGUAGE="javascript">
<!--Hide
name_off=new Image(93,18)
name_off.src="name_off.gif"
name_on=new Image(93,18)
name_on.src="name_on.gif"
newname_off=new Image(93,18)
newname_off.src="newname_off.gif"
newname_on=new Image(93,18)
newname_on.src="newname_on.gif"
//End hide-->
</Script>
This is where you want your images on the page.
<A HREF="name.html" onmouseover="document.whatever.src=name_on.src" onmouseout="document.whatever.src=name_off.src"><IMG SRC="name_off.gif" NAME="whatever" BORDER=0 HEIGHT=18 WIDTH=93></A>
<A HREF="newname.html" onmouseover="document.newwhatever.src=newname_on.src" onmouseout="document.newwhatever.src=newname_off.src"><IMG SRC="newname_off.gif" NAME="newwhatever" BORDER=0 HEIGHT=18 WIDTH=93></A>
ShrineDesigns
12-15-2002, 07:41 PM
that's almost the same script dada was using. he just modify to the point were it wouldn't work properly
and i am sure that he plans on expanding beyond just two images resulting in a script that is a mile long
I just didn't know if the Dreamweaver script was copyright. I thought about posting it, but didn't want to risk it. It looks like my script is pretty close to what he was doing, not the Dreamweaver one.
ShrineDesigns
12-15-2002, 08:30 PM
you can't copyright javascript can you ???
I doubt it, but since there were other ways of doing it, I decided to show one of those other ways. I've never heard of copyrighting it, but I didn't know. Anyone? it would be nice to know...I've been wondering about that, too.
Thanks for the help, I'll give it a try and see what happens.