如何使用JavaScript计算div身高?
How to calculate div height using JavaScript?
我开发了一些 html 页面。我想在更改页面时适应侧边菜单 div 高度
<div> <!-- menu div-->
</div>
<div> <!-- content div-->
</div>
当更改内容div高度时,要在菜单div中更改相同的高度。当显示隐藏字段更改内容 div 高度时,我想将菜单 div 高度调整为相同的高度。我在 jquery 或 JavaScript.
中寻找答案
看看
https://api.jquery.com/resize/
和 http://api.jquery.com/height/
$('div').height();
或
$('div').resize();
你可以使用 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);
我开发了一些 html 页面。我想在更改页面时适应侧边菜单 div 高度
<div> <!-- menu div-->
</div>
<div> <!-- content div-->
</div>
当更改内容div高度时,要在菜单div中更改相同的高度。当显示隐藏字段更改内容 div 高度时,我想将菜单 div 高度调整为相同的高度。我在 jquery 或 JavaScript.
中寻找答案看看 https://api.jquery.com/resize/ 和 http://api.jquery.com/height/
$('div').height();
或
$('div').resize();
你可以使用 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);