萬盛學電腦網

 萬盛學電腦網 >> 腳本專題 >> javascript >> js實現鼠標滑過文字鏈接色彩變化的效果

js實現鼠標滑過文字鏈接色彩變化的效果

   本文實例講述了js實現鼠標滑過文字鏈接色彩變化效果的方法。分享給大家供大家參考。具體實現方法如下:

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>鼠標移入移出效果</title> <style> body,ul,h2,p{ margin:0; padding:0; font-family:"微軟雅黑"; background:#333; } li{list-style:none;} a{text-decoration:none;} #box{ width:270px;padding:10px 10px 20px; overflow:hidden;margin:20px auto 0; border:1px solid #FFF; } .internal{width:266px;float:left;} #box h2{ height:38px;border-bottom:1px solid #ccc; padding-left:5px; } #box h2 strong{ float:left; line-height:38px; color:#885050; } #box h2 a{ float:right;width:52px;height:14px; font-size:12px;text-indent:20px; color:#fff;line-height:12px; font-weight:normal;margin-top:10px; } #box li{ height:30px;position:relative; border-bottom:1px dashed #ccc; } #box li div,#box li p{ height:30px;position:absolute; top:0;left:0;width:100%; } #box li p{ background:#fff;opacity:0; filter:alpha(opacity=0); } #box li div a,#box li div span{ line-height:30px; font-size:12px;height:30px; } #box li div a { float:left;padding-left:5px; color:#7F5454;width:185px; overflow:hidden; } #box li div span{ padding-right:10px; float:right;color:#CF9494; } </style> <script type="text/javascript"> window.onload=function() { var d=document; var oBox=d.getElementById('box'); var aLi=oBox.getElementsByTagName('li'); var i=0; for(i=0;i<aLi.length;i++) { var oP=aLi[i].getElementsByTagName('p')[0]; oP.iAlpha=0; oP.times=null; aLi[i].onmouseover=function() { oP=this.getElementsByTagName('p')[0]; oP.times && clearInterval(oP.times); oP.style.opacity=1; oP.style.filter="alpha(opacity=100)"; oP.iAlpha=100; }; aLi[i].onmouseout=function() { startMove(this.getElementsByTagName('p')[0]) }; } }; function startMove(obj) { obj.times && clearInterval(obj.time); obj.times=setInterval(function() { doMove(obj); },10); } function doMove(obj) { var iSpeed=5; if(obj.iAlpha<=iSpeed) { clearInterval(obj.times); obj.iAlpha=0; obj.time=null; } else { obj.iAlpha-=iSpeed; } obj.style.filter="alpha(opacity="+obj.iAlpha+")"; obj.style.opacity=obj.iAlpha/100; } </script> </head> <body> <div id="box"> <div class="internal"> <h2><strong>網頁特效代碼</strong> <a href="http://www.3lian.net/">more</a></h2> <ul> <li> <p></p> <div> <a href="http://www.3lian.net/"> 廣告代碼特效大全 </a> <span>2011-09-10</span> </div> </li> <li> <p></p> <div> <a href="http://www.3lian.net/"> JS特效代碼集錦 </a> <span>2011-09-10</span> </div> </li> <li> <p></p> <div> <a href="http://www.3lian.net/">商業網頁模板與光盤素材</a> <span>2011-09-10</span> </div> </li> <li>
copyright © 萬盛學電腦網 all rights reserved