简体   繁体   English

jQuery动态Div高度

[英]Jquery Dynamic Div Height

$('#menu-window-inner').css(
    {'height':
        ( 
            ($('#menu-window').height()) - 
            ($('#menu-window-title').height()) -
            ($('#menu-window-footer').height()) 
        )
    }
);

So I'm trying to use the code above to set the height of "menu-window-inner". 因此,我试图使用上面的代码来设置“菜单窗口内部”的高度。 It works when I use the equation X=AB, but not when I use X=ABC. 当我使用公式X = AB时,它起作用,但是当我使用X = ABC时,它不起作用。 Basically it only works when subtracting the height of one div, not two. 基本上,仅当减去一格的高度而不是二格的高度时,它才有效。

Anyone know the correct fix? 有人知道正确的解决方法吗? Having read over the code and css it all looks correct to me so I'm bamboozled. 阅读完代码和css后,对我来说一切都正确,所以我为之着迷。

you can use outerHeight() and height() functions of jQuery here: 您可以在此处使用jQuery的outsideHeight()和height()函数:

$('#menu-window-inner').height(
    $('#menu-window').outerHeight() - 
    $('#menu-window-title').outerHeight() - 
    $('#menu-window-footer').outerHeight()
);

and your code is not working because wou need to append "px" at the end of the value when using CSS height property. 并且您的代码无法正常工作,因为使用CSS height属性时,您需要在值的末尾附加“ px”。

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

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