为什么加了clearInterval(This.time); 之后就没有伸缩的效果了

<!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">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

<style type="text/css">

*{margin:0;padding:0;}

ul{list-style:none ;height:50px;padding-left:30px;border-bottom:5px solid #F90;}

a{text-decoration:none;display:block;height:30px;line-height:30px;width:120px;background-color:#C33;margin-bottom:1px;text-align:center;}

li{float:left;margin-top:20px;}

.on,a:hover{background-color:#F93;height:40px;margin-top:-10px;line-height:40px;}

</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(){

clearInterval(This.time);

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(){

clearInterval(This.time);

var This=this;

This.time=setInterval(function(){

This.style.width=This.offsetWidth+8+"px";

if(This.offsetWidth>=120){

This.style.width="120px";

clearInterval(This.time);

}

},30)

}





}

}


</script>

</head>

<body>

<ul>

      <li><a class= "on"href="#">首页</a></li>

      <li><a href="#">新闻快讯</a></li>

      <li><a href="#">产品展示</a></li>

      <li><a href="#">快线</a></li>

</ul>

</body>



</html>


FDU_XN
浏览 2257回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript