为了账号安全,请及时绑定邮箱和手机立即绑定

mouseover在二级菜单上 为什么会抖​

 for(var i=0;i<Lis.length;i++)    
        {  Lis[i].onmouseover=function (){
           
             var u = this.getElementsByTagName("ul")[0];
             u.style.display = "block";
                    if (u != undefined) {
                        ChangeH(u.id,1);
                    }
           
        }     
               
               
               
               
                Lis[i].onmouseout = function () {
                    var u = this.getElementsByTagName("ul")[0];
                    if (u != undefined) {
                        ChangeH(u.id,-1);
                    }
                }
            }
        }

        function ChangeH(id, count) {
    // 根据ID找到ulList,同时得到其高度
            var ulList = document.getElementById(id);
            var h = ulList.offsetHeight;
   
            h += count;
            if (count > 0) {
                if (h <= 42) {
   // 将高度赋值给ulList,同时,不断调用本函数
                    ulList.style.height = h + "px";
                    setTimeout("ChangeH('" + id + "',1)", 10);
                }
                else {
                    return;
                }
            }
            else {
                if (h > 0) {
  // 将高度赋值给ulList,同时,不断调用本函数
                    ulList.style.height = h + "px";
                    setTimeout("ChangeH('" + id + "',-1)", 10);
                }
                else {
                    ulList.style.display = "none";
                    return;
                }
            }
        }

正在回答

1 回答

 var u = this.getElementsByTagName("ul")[0];
  u.style.display = "block";//应该先判断ul元素是否存在,再修改它的style属性下的display属性
  if (u != undefined) 
   {
         ChangeH(u.id,1);
   }

即,改为

var u = this.getElementsByTagName("ul")[0];
  
 if (u != undefined)
  {

     u.style.display = "block";                            

    ChangeH(u.id,1);
  }

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
形形色色的下拉菜单
  • 参与学习       107006    人
  • 解答问题       542    个

本教程从易到难,循循渐进,运用不同技术实现动态下拉菜单

进入课程

mouseover在二级菜单上 为什么会抖​

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信