代码之家  ›  专栏  ›  技术社区  ›  Marlon Creative

需要帮助修复此jQuery下拉脚本吗

  •  0
  • Marlon Creative  · 技术社区  · 16 年前


     $j('ul.menu > li').hover(
    
        function() { var ulHeight = $j('ul', this).height(); $j(this).children('ul').css({height: 0}).stop().animate({height: ulHeight}, 400); },
        function() { $j(this).children('ul').stop().animate({height: 0}, 400);   }
    );
    

    我需要将UL的高度恢复到其原始大小,并将显示器设置为“无”,以便它可以再次运行。现在的情况是,离开时高度设置为0,下次取“ulHeight”时,高度为0。

    我这样试过,但没有乐趣:


     function() { $j(this).children('ul').stop().animate({height: 0}, 400).css({height: ulHeight});   }
    

    有人有什么想法吗?

    2 回复  |  直到 16 年前
        1
  •  1
  •   Mottie    16 年前

    您的子菜单根本不显示。。。

    但归根结底,为什么要重新发明轮子呢? http://css-tricks.com/simple-jquery-dropdowns/ Superfish


    .css({"display": "block"});
    .css({"display": "none"});
    

    具有

    .show();
    .hide();
    

    分别,您可以使用 .hover 而不是 .mouseenter .mouseleave

    here ... 我无法在jsbin中编辑您的代码(编辑窗口有3行高,我无法滚动),因此我将其重新发布到pastebin。

        2
  •  0
  •   slikts    16 年前

    “高度”特性的默认值为 auto 0 ,藏起来的时候。