Javascriptでの画像置換
html&cssの画像置換
<html> <head> <style type="text/css"> ul{ width: 800px; margin: 50px 0 0 50px; list-style: none; overflow: hidden; } li{ float: left; display: inline; } li a{ width: 160px; height: 50px; display: block; text-decoration: none; float: left; display: inline; } li#home a{ background: #ffffff url(Js_button/button_01.png) no-repeat top left; } li#home a:hover{ background: url(Js_button/button_01_o.png) no-repeat top left; } li#html a{ background: #ffffff url(Js_button/button_02.png) no-repeat top left; } li#html a:hover{ background: url(Js_button/button_02_o.png) no-repeat top left; } li#as a{ background: #ffffff url(Js_button/button_03.png) no-repeat top left; } li#as a:hover{ background: url(Js_button/button_03_o.png) no-repeat top left; } li#js a{ background: #ffffff url(Js_button/button_04.png) no-repeat top left; } li#js a:hover{ background: url(Js_button/button_04_o.png) no-repeat top left; } li#ph a{ background: #ffffff url(Js_button/button_05.png) no-repeat top left; } li#ph a:hover{ background: url(Js_button/button_05_o.png) no-repeat top left; } em{ visibility: hidden; } </style> </head> <body> <ul> <li id="home"><a href=""><em>Home</em></a></li> <li id="html"><a href=""><em>Html&Css</em></a></li> <li id="as"><a href=""><em>ActionScript</em></a></li> <li id="js"><a href=""><em>JavaScript</em></a></li> <li id="ph"><a href=""><em>PHP</em></a></li> </ul> </body> </html>
簡単なjavascriptの画像置換
<html> <head> <style type="text/css"> ul{ width: 800px; margin: 50px 0 0 50px; list-style: none; overflow: hidden; } li{ float: left; list-style: none; display: inline; } </style> </head> <body> <ul> <li><a href=""><img src="Js_button/button_01.png" alt="" width="160" height="50" onMouseOver="this.src='Js_button/button_01_o.png'" onMouseOut="this.src='Js_button/button_01.png'"></a></li> <li><a href=""><img src="Js_button/button_02.png" alt="" width="160" height="50" onMouseOver="this.src='Js_button/button_02_o.png'" onMouseOut="this.src='Js_button/button_02.png'"></a></li> <li><a href=""><img src="Js_button/button_03.png" alt="" width="160" height="50" onMouseOver="this.src='Js_button/button_03_o.png'" onMouseOut="this.src='Js_button/button_03.png'"></a></li> <li><a href=""><img src="Js_button/button_04.png" alt="" width="160" height="50" onMouseOver="this.src='Js_button/button_04_o.png'" onMouseOut="this.src='Js_button/button_04.png'"></a></li> <li><a href=""><img src="Js_button/button_05.png" alt="" width="160" height="50" onMouseOver="this.src='Js_button/button_05_o.png'" onMouseOut="this.src='Js_button/button_05.png'"></a></li> </ul> </body> </html>
Dreamweaverビヘイビアでの画像置換
これはうまくいかない
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> *{ margin: 0; padding: 0; } ul{ margin: 50px 0 0 50px; } ul li{ list-style: none; float: left; } </style> <script 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 onmouseover="MM_swapImage('home','','Js_button/button_01_o.png','html','','Js_button/button_02_o.png','as','','Js_button/button_04_o.png','js','','Js_button/button_03_o.png','php','','Js_button/button_05_o.png',0)" onmouseout="MM_swapImage('home','','Js_button/button_01.png','html','','Js_button/button_02.png','as','','Js_button/button_04.png','js','','Js_button/button_03.png','php','','Js_button/button_05.png',1)"> <ul> <li><a href="#"><img src="Js_button/button_01.png" id="home" width="160" height="50" alt="home"></a></li> <li><a href="#"><img src="Js_button/button_02.png" id="html" width="160" height="50" alt="html"></a></li> <li><a href="#"><img src="Js_button/button_04.png" id="as" width="160" height="50"></a></li> <li><a href="#"><img src="Js_button/button_03.png" id="js" width="160" height="50" alt="js"></a></li> <li><a href="#"><img src="Js_button/button_05.png" id="php" width="160" height="50" alt="php"></a></li> </ul> </body> </html>