?下拉菜單動畫js部分代碼 : ? ? ?var aLi=document.getElementsByTagName('li'); for(var i=0; i<aLi.length; i++) { ?aLi[i].onmouseover=function() ?{? ? ? ? ?var oSubNav=this.getElementsByTagName('ul')[0];? ? ? ? ?var This=oSubNav;? ? ? ? ? ? clearInterval(This.time);? ? ? ? ? ? This.time=setInterval(function()? ? ? ? ? ? {? ? ? ? ? ? ? ? ? ? This.style.height=This.offsetHeight+16+"px";? ? ? ? ? ? ? ? ? ? if(This.offsetHeight>=120)? ? ? ? ? ? ? ? ? ? {clearInterval(This.time);} alert("動畫里this:"+This.offsetHeight); alert("動畫里oSubNav:"+oSubNav.offsetHeight);? ? ? ? ? ? },30)? ?? }?代碼中的變量oSubNav為什么要重新賦值給變量This?我在動畫效果函數(shù)中試了下,能成功調(diào)用oSubNAv,它的當(dāng)前高度屬性值也與This一樣。然而在函數(shù)中直接用oSubNav.style.height=oSubNav.offsetHeight+16+"px";為什么不產(chǎn)生動畫?
js動畫中的this
艾零
2017-07-20 12:31:20