做出来二级菜单会出现闪烁延迟现象,是怎么回事?
</style>
<script>
window.onload=function(){
var aLi=document.getElementsByTagName('li');
for(var i=0; i<aLi.length; i++){
aLi[i].onmouseover=function(){
//鼠标经过一级菜单,二级菜单动画下拉显示出来
var sub=this.getElementsByTagName('ul')[0];
if(sub){
var This=sub;
clearInterval(This.time);
This.time=setInterval(function(){
This.style.height=This.offsetHeight+16+"px";
if(This.offsetHeight>=120){
clearInterval(This.time);
}
},30);
}
}
//鼠标离开菜单,二级菜单动画收缩起来。
aLi[i].onmouseout=function(){
var sub=this.getElementsByTagName('ul')[0];
if(sub){
This=sub;
clearInterval(This.time);
This.time=setInterval(function(){
This.style.height=This.offsetHeight-16+"px";
if(This.offsetHeight<0){
This.offsetHeight="0 px";
clearInterval(This.time);
}
},30);
}
}
}
}
</script>