<!DOCTYPE?html>
<html>
??<head>
????<meta?charset="utf-8">
????<title>導(dǎo)航欄</title>
????<style?media="screen">
??????ul{
????????list-style:?none;
????????width:?800px;
????????height:50px;
????????border-bottom:?5px?solid?rgb(14,?79,?126);
??????}
??????a{
????????text-align:?center;
????????display:?block;
????????width:?100px;
????????text-decoration:?none;
????????font-family:?黑體;
????????color:?rgb(0,0,0);
????????line-height:?30px;
????????font-size:?20px;
????????background:?rgb(189,?108,?108);
????????padding:?5px;
????????border-top-right-radius:?8px;
????????border-top-left-radius:?8px;
??????}
??????/*a:hover,a.on{
????????background:?rgb(29,?62,?122);
????????color:white;
????????width:?150px;
??????}*/
??????li{
????????float:?left;
????????margin-top:10px;
??????}
????</style>
????<script?type="text/javascript">
??????window.onload=function(){
????????var?oNav=document.getElementsByTagName('ul')[0];
?????? var?aA=oNav.getElementsByTagName('a');
????????for(var?i=0;?i<aA.length;?i++){
?????? aA[i].onmouseover=function(){
?????? if(this.className!="on"){
?????? clearInterval(this.timer);
?????? var?This=this;
?????? This.time=setInterval(function(){
?????? This.style.width=This.offsetWidth+8+"px";
?????? if(This.offsetWidth>=120)
?????? clearInterval(This.time);
?????? },30)
?????? }
?????? }
?????? aA[i].onmouseout=function(){
?????? if(this.className!="on"){
?????? clearInterval(this.time);
?????? var?This=this;
?????? this.time=setInterval(function(){
?????? This.style.width=This.offsetWidth-8+"px";
?????? if(This.offsetWidth<=80){
?????? This.style.width='80px';
?????? clearInterval(This.time);
?????? }
?????? },30)
?????? }
?????? }
?????? }
??????}
????</script>
??</head>
??<body>
????<ul>
??????<li><a?class="on"?href="#">首    頁</a></li>
??????<li><a?href="#">新聞快訊</a></li>
??????<li><a?href="#">產(chǎn)品展示</a></li>
??????<li><a?href="#">售后服務(wù)</a></li>
??????<li><a?href="#">聯(lián)系我們</a></li>
????</ul>
??</body>
</html>
2016-12-16
把a標簽里的padding拿掉。清除動畫里的是this.time不是this.timer。