繁体   English   中英

如何为div添加“ auto”值?

[英]How can I add value “auto” to a div?Jquery

代码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为值344 ,而不是值344

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

var subMenuHeight = "auto";

您能告诉我这个问题的解决方案吗? 谢谢!

如果要将高度设置为自动,则必须删除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');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM