为什么我的鼠标移除后就无限加长?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
ul {
list-style: none;
margin: 0;
padding: 0;
overflow: auto;
background-color: antiquewhite;
position: fixed;
top: 0;
/*改为bottom:0;就是固定在底部*/
width: 100%;
}
li {
float: left;
border-right: 1px solid black;
/*在右边添加分割线*/
}
li:last-child {
border-right: none;
}
li a {
display: block;
width: 60px;
text-decoration: none;
color: black;
padding: 8px 20px;
}
li a:hover:not(.active) {
background-color: deepskyblue;
color: greenyellow;
}
li a.active {
background-color: greenyellow;
color: red;
}
</style>
<script>
window.onload = function() {
var aA = document.getElementsByTagName("a");
for(var i = 0; i < aA.length; i++) {
aA[i].onmouseover = function() {
clearInterval(this.time)
var This = this;
This.time = setInterval(function() {
This.style.width = This.offsetWidth + 8 + "px";
if(This.offsetWidth >= 100) {
clearInterval(This.time)
}
}, 30)
}
aA[i].onmouseout = function() {
clearInterval(this.time)
var This = this;
This.time = setInterval(function() {
This.style.width = This.offsetWidth - 8 + "px";
if(This.offsetWidth <= 60) {
This.style.width = "60px"
setInterval(This.time)
}
}, 30)
}
}
}
</script>
</head>
<body>
<ul>
<li>
<a href="#">主页</a>
</li>
<li>
<a href="#">新闻</a>
</li>
<li>
<a href="#">联系</a>
</li>
<li>
<a href="#">B站</a>
</li>
<li style="float: right;">
<a class="active" href="#">关于</a>
</li>
</ul>
</body>
</html>