為什么我這個(gè)鼠標(biāo)移開(kāi)沒(méi)有隱藏二級(jí)菜單?
<script>
window.onload=function(){
? ? var aLi=document.getElementsByTagName('li');
for(var i=0; i<aLi.length; i++){
aLi[i].onmouseover=function(){
? ? ? ? ? ? //鼠標(biāo)經(jīng)過(guò)一級(jí)菜單,二級(jí)菜單動(dòng)畫下拉顯示出來(lái)
? ? ? ? var oSubNav = this.getElementsByTagName('ul')[0];
? ? ? ? if(oSubNav) {
? ? ? ? ? ? var This = oSubNav;
? ? ? ? ? ? clearInterval(This.time);
? ? ? ? ? ? This.time=setInterval(function(){
? ? ? ? ? ? ? ? This.style.height=This.offsetHeight+16+"px";
? ? ? ? ? ? ? ? if(This.offsetHeight>=120)
? ? ? ? ? ? ? ? clearInterval(This.time);
? ? ? ? ? ? ? ? },30)
? ? ? ? }
}
? ? ? ? //鼠標(biāo)離開(kāi)菜單,二級(jí)菜單動(dòng)畫收縮起來(lái)。
aLi[i].onmouseout=function(){
var oSubNav=this.getElementsByTagName('ul')[0];
if(oSubNav){
? var This = oSubNav;
? clearInterval(This.time);
? This.time=setInterval(function(){
? ? ? This.style.height=This.offSetHeight-16+"px";
? ? ? if(This.offsetHeight<=0){
? ? ? ? ? This.style.height=0;
? ? ? ? ? This.style.overflow = hidden;
? ? ? ? ? clearInterval(This.time);
? ? ? }
? ? ? },30)
}
}
}
}
</script>
2019-07-30
?問(wèn)題找到了,offSetHeight這里拼錯(cuò)了 ,頭大了。。。。