调整窗口大小时更新窗口内部高度

Update window innerheight when resizing window

本文关键字:窗口 内部 高度 更新 小时 调整      更新时间:2023-09-26

到目前为止,我已经成功地创建了一个Id,使其具有与窗口相同的innerHeight。然而,当我调整窗口大小时,高度保持不变。

有人能帮我在调整窗口大小时使Id与窗口的innerHeight相同吗?这是代码

function height()
{
var h = window.innerHeight;
document.getElementById("id").style.height = h+'px'; 
}
height();

这种方法可能会更好地处理现有的事件处理程序:

window.addEventListener('resize',function(){
  document.getElementById("id").style.height = window.innerHeight + 'px';
});

您可以使用:

window.onresize = function(event) {
    var h = window.innerHeight;
    document.getElementById("id").style.height = h+'px'; 
};