为什么This.style.width=This.offsetWidth-8+"px"; 没有效果,而且更糟糕了
<!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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<style type="text/css">
*{margin: 0;padding: 0;}/*清除一下页面的样式*/
ul{
list-style: none;/*清除一下ul的符号*/
height: 50px;
border-bottom: 5px solid #f60;
}
li{
float: left;
padding-top: 20px;
}
a{
display: block;
text-align: center;
text-decoration: none;/*将a的下划线不显示*/
height: 30px;
line-height: 30px;
width: 100px;
background-color: #ccc;
margin-bottom: 1px;
padding-left: 10px;
border-radius: 10px 10px 0 0 ;
}
.on ,a:hover{
background-color: #f60;
color: #fff;
}
</style>
<script type="text/javascript">
window.onload=function(){
var aA=document.getElementsByTagName("a");
for(var i=0;i<aA.length;i++){
aA[i].onmouseover=function(){
var This=this;
clearInterval(time);
var time= setInterval(
function(){
This.style.width=This.offsetWidth+8+"px";
if(This.offsetWidth>=160){
clearInterval(time);
}
},30);
};
aA[i].onmouseout=function(){
var This=this;
clearInterval(time);
var time= setInterval(
function(){
This.style.width=This.offsetWidth-8+"px";
if(This.offsetWidth<=120){
clearInterval(time);
}
},30);
};
}
};
</script>
</head>
<body>
<ul>
<li><a href="#">首 页</a></li>
<li><a href="#">新闻快讯</a></li>
<li><a href="#">产品展示</a></li>
<li><a href="#">售后服务</a></li>
<li><a href="#">联系我们</a></li>
</ul>
</body>
</html>