View: 2393|Reply: 2
|
tolong tengokkan coding ni...
[Copy link]
|
|
aku nak buat onmouseover, kat firefox ok...tapi kat IE tak ok..image onmouseover tu tak kuar...tolong aku
ni codingnya...
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a)&&x.oSrc;i++) x.src=x.oSrc;
}
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.indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}}
}
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[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document); 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))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
ni kat body....
<TD width="61"><a href="intro.htm" ><img src="images/home.jpg" name="Image10" border="0" height="36" width="61"></a></TD>
<TD width="78"><a href="about.htm" ><img src="images/about.jpg" name="Image11" border="0" height="36" width="78"></a></TD>
<TD width="86"><a href="services.htm" ><img src="images/services.jpg" name="Image12" border="0" height="36" width="86"></a></TD>
<TD width="86"><a href="client.htm" ><img src="images/client.jpg" name="Image13" border="0" height="36" width="86"></a></TD>
<TD width="71"><a href="contact.htm" ><img src="images/contact.jpg" name="Image14" border="0" height="36" width="71"></a></TD>
apa yg salah ni eh?
|
|
|
|
|
|
|
|
coding yg ko paste ni complete x ?? aku x ley nk trace lak kt ner ko nye event mouseover/mouseout trigger ...
Anyway ... aku prepare kn ko script ringkas kalo ko nk try ... aku based on ko nye bahagian body tu ... tested on IE6, IE7, Mozilla 3, Opera 9
<script type="text/javascript">
function swapIn(obj,imgIndex){
var imgList = new Array("homeA.jpg","aboutA.jpg","servicesA.jpg","clientA.jpg","contactA.jpg"); // Senarai gambar untuk mouseover
obj.src = "images/" + imgList[imgIndex];
}
function swapOut(obj,imgIndex){
var imgList = new Array("home.jpg","about.jpg","services.jpg","client.jpg","contact.jpg"); // Senarai gambar asal
obj.src = "images/" + imgList[imgIndex];
}
</script>
<------body-------->
<TD width="61"><a href="intro.htm" ><img src="images/home.jpg" border="0" height="36" width="61" ></a></TD>
<TD width="78"><a href="about.htm" ><img src="images/about.jpg" border="0" height="36" width="78" ></a></TD>
<TD width="86"><a href="services.htm" ><img src="images/services.jpg" border="0" height="36" width="86" ></a></TD>
<TD width="86"><a href="client.htm" ><img src="images/client.jpg" border="0" height="36" width="86" ></a></TD>
<TD width="71"><a href="contact.htm" ><img src="images/contact.jpg" border="0" height="36" width="71" ></a></TD>
[ Last edited by digitalgunner at 25-11-2008 08:06 AM ] |
|
|
|
|
|
|
|
Kalau nk simplify sket coding atas ... wat cmni :
Make sure sume file gambar utk mouseover tu ada tambahan "_hover" pada nama file. cth: home.jpg (asal); home_hover.jpg (gambar kedua)
<script type="text/javascript">
function swapIn(obj){
obj.src = obj.src.replace(".jpg","_hover.jpg");
}
function swapOut(obj){
obj.src = obj.src.replace("_hover.jpg",".jpg");
}
</script>
Kat body:
<TD width="61"><a href="intro.htm"><img src="images/home.jpg" border="0" height="36" width="61" onmouseover="swapIn(this);" onmouseout="swapOut(this);"/></a></TD>
<TD width="78"><a href="about.htm"><img src="images/about.jpg" border="0" height="36" width="78" onmouseover="swapIn(this);" onmouseout="swapOut(this);"/></a></TD>
<TD width="86"><a href="services.htm"><img src="images/services.jpg" border="0" height="36" width="86" onmouseover="swapIn(this);" onmouseout="swapOut(this);"/></a></TD>
<TD width="86"><a href="client.htm"><img src="images/client.jpg" border="0" height="36" width="86" onmouseover="swapIn(this);" onmouseout="swapOut(this);"/></a></TD>
<TD width="71"><a href="contact.htm"><img src="images/contact.jpg" border="0" height="36" width="71" onmouseover="swapIn(this);" onmouseout="swapOut(this);"/></a></TD> |
|
|
|
|
|
|
| |
|