google首页的动态菜单代码

有待完善,写的比较丑陋!代码如下:

XML/HTML代码
  1. <style type="text/css">
  2. #nav{padding:0px; margin:0px; list-style:none;}
  3. #nav li{font-size:12px; cursor:pointer; padding-top:37px; width:52px; text-align:center; float:left; background: url(http://www.junstyle.com.cn/upload/200906012008252720.png) no-repeat 0px 0px;}
  4. #nav li div{background:#fff; padding-top:3px;}
  5. </style>
  6. <ul id="nav">
  7. <li style="background-position: 0px 0px"><div>视频</div></li>
  8. <li style="background-position: 0px -37px"><div>图片</div></li>
  9. <li style="background-position: 0px -74px"><div>资讯</div></li>
  10. <li style="background-position: 0px -111px"><div>地图</div></li>
  11. <li style="background-position: 0px -148px"><div>博客搜索</div></li>
  12. <li style="background-position: 0px -185px"><div>热榜</div></li>
  13. <li style="background-position: 0px -222px"><div>网站导航</div></li>
  14. </ul>
  15. <script>
  16. var timers=[];
  17. var posX=[0, -50, -102, -155, -207];
  18. var posY=[0, -37, -74, -111, -148, -185, -222];
  19. function init(){
  20. var nav = document.getElementById('nav').getElementsByTagName('li');
  21. for(var i=0; i<nav.length; i++){
  22. nav[i].i=i;
  23. nav[i].onmouseover=function(){
  24. var obj=this;
  25. obj.index=0; &nbs
    p;
  26. clearInterval(timers[obj.i]);
  27. timers[obj.i]=setInterval(function(){
  28. if(obj.index==4)
  29. clearInterval(timers[obj.i]);
  30. else
  31. obj.index=obj.index+1;
  32. obj.style.background="url(http://www.junstyle.com.cn/upload/200906012008252720.png) no-repeat "+posX[obj.index]+"px "+posY[obj.i]+"px";
  33. }, 60);
  34. };
  35. nav[i].onmouseout=function(){
  36. var obj=this;
  37. obj.index=4;
  38. clearInterval(timers[obj.i]);
  39. timers[obj.i]=setInterval(function(){
  40. if(obj.index==0)
  41. clearInterval(timers[obj.i]);
  42. else
  43. obj.index=obj.index-1;
  44. obj.style.background="url(http://www.junstyle.com.cn/upload/200906012008252720.png) no-repeat "+posX[obj.index]+"px "+posY[obj.i]+"px";
  45. }, 60);
  46. };
  47. }
  48. }
  49. init();
  50. </script>