横向滑动特效的菜单(js+css)_网页代码站(www.webdm.cn)
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title>横向滑动特效的菜单(js+css)_网页代码站(www.webdm.cn)</title>
5 <style>
6 * {margin:0; padding:0}
7 body {font:14px Helvetica, sans-serif; font-weight:bold; background:#FFF}
8 .menu {position:relative; background:url(http://www.webdm.cn/images/20090910/bgx.gif) no-repeat; height:35px; width:459px}
9 .menu ul {list-style:none; z-index:10; position:absolute; z-index:100; padding:9px 5px}
10 .menu li {float:left}
11 .menu a, .menu a:active, .menu a:visited {text-decoration:none; color:#FFF; padding:10px}
12 .menu a:hover {color:#ebf0e6}
13 #slide {position:absolute; bottom:0; height:4px; background:#89957a; z-index:10}
14 </style>
15 <script type="text/javascript" language="javascript">
16 var menuSlider=function(){
17 var m,e,g,s,q,i; e=[]; q=8; i=8;
18 return{
19 init:function(j,k){
20 m=document.getElementById(j); e=m.getElementsByTagName('li');
21 var i,l,w,p; i=0; l=e.length;
22 for(i;i<l;i++){
23 var c,v; c=e[i]; v=c.value; if(v==1){s=c; w=c.offsetWidth; p=c.offsetLeft}
24 c.onmouseover=function(){menuSlider.mo(this)}; c.onmouseout=function(){menuSlider.mo(s)};
25 }
26 g=document.getElementById(k); g.style.width=w+'px'; g.style.left=p+'px';
27 },
28 mo:function(d){
29 clearInterval(m.tm);
30 var el,ew; el=parseInt(d.offsetLeft); ew=parseInt(d.offsetWidth);
31 m.tm=setInterval(function(){menuSlider.mv(el,ew)},i);
32 },
33 mv:function(el,ew){
34 var l,w; l=parseInt(g.offsetLeft); w=parseInt(g.offsetWidth);
35 if(l!=el||w!=ew){
36 if(l!=el){var ld,lr,li; ld=(l>el)?-1:1; lr=Math.abs(el-l); li=(lr<q)?ld*lr:ld*q; g.style.left=(l+li)+'px'}
37 if(w!=ew){var wd,wr,wi; wd=(w>ew)?-1:1; wr=Math.abs(ew-w); wi=(wr<q)?wd*wr:wd*q; g.style.width=(w+wi)+'px'}
38 }else{clearInterval(m.tm)}
39 }};}();
40 </script>
41 </head>
42 <body onload="menuSlider.init('menu','slide')">
43 <div class="menu">
44 <ul id="menu">
45 <li><a href="http://www.webdm.cn/">JavaScript</a></li>
46 <li><a href="#">网页代码站</a></li>
47 <li><a href="#">HTML</a></li>
48 <li value="1"><a href="http://www.webdm.cn/">网页特效</a></li>
49 <li><a href="http://www.webdm.cn/">CSS</a></li>
50 </ul>
51 <div id="slide"><!-- --></div>
52 </div>
53 </body>
54 </html>
55 <br>
56 <a href="http://www.webdm.cn">网页代码站</a> - 最专业的代码下载网站 - 致力为中国站长提供有质量的代码!
文章来自:http://www.webdm.cn/webcode/08428d1e-8206-4a64-8258-2f2bf9f8c245.html