Javascript 我怎样才能增值;“自动”;到div?Jquery

Javascript 我怎样才能增值;“自动”;到div?Jquery,javascript,jquery,html,css,Javascript,Jquery,Html,Css,代码JS: $('.i_admin_user a').click(function(){ var liHeight = $('.subMenu-1 > li').height() - 1; var subMenuHeight = 344; //here I want auto value; $(this).parent().siblings('li').children('.subMenu-1').animate({height:0},

代码JS:

$('.i_admin_user a').click(function(){

        var liHeight = $('.subMenu-1 > li').height() - 1;
        var subMenuHeight = 344;  //here I want auto value;

        $(this).parent().siblings('li').children('.subMenu-1').animate({height:0},300);
        $(this).siblings('.subMenu-1').animate({ height: subMenuHeight + 'px'},300)
           .addClass('active-submenu');

        if( $('.subMenu-1').hasClass('active-submenu')){
                $(this).siblings('.subMenu-1').removeClass('active-submenu');
        }else{

        }

    });
我如何修改我的代码,使他们接受和重视“自动”

基本上,我希望将值
auto

我尝试了下一个版本,但不起作用(在本例中,返回的高度为0)

你能告诉我这个问题的解决办法吗?
谢谢大家!

如果要将高度设置为自动,则必须删除
px

像这样:

var subMenuHeight = 'auto';  // auto value here

$(this).siblings('.subMenu-1').animate({ height: subMenuHeight},300).addClass('active-submenu');
如果不删除
px
,它将不会重新初始化自动,因为该值是
autopx
,您可以尝试以下操作:

$(this).siblings('.subMenu-1').animate( height:auto},300).addClass('active-submenu');

我不明白你的标题和实际问题之间的关系?给你一个提示:你正在写
subMenuHeight+'px'
,但是如果
subMenuHeight
设置为
auto
,这将是完全错误的,因为没有值
autopx
。在这种情况下,
px
必须省略对不起,标题是我的错。。。我修好了
$(this).siblings('.subMenu-1').animate( height:auto},300).addClass('active-submenu');