如何使用JavaScript计算div高度?

时间:2016-04-08 13:14:00

标签: javascript jquery html

我开发了一些html页面。我想在更改页面div高度时适合侧边菜单

<div>  <!-- menu div-->
</div> 
<div>  <!-- content div-->
</div>

当更改内容div 高度时,要在菜单div中更改相同的高度。当显示隐藏字段更改内容div高度时,我想调整相同高度的菜单div高度。我在 jquery JavaScript 中寻找答案。

2 个答案:

答案 0 :(得分:2)

看看 https://api.jquery.com/resize/http://api.jquery.com/height/

$('div').height();

$('div').resize();

答案 1 :(得分:1)

您可以使用bind/trigger

$('#content-div').bind('heightChange', function(event, newHeight){
  $('#main-div').height(newHeight);
});

并触发div高度变化事件:

var newHeight = 200;
$('#content-div').css('height', newHeight);
$("#content-div").trigger('heightChange', newHeight);
相关问题