调整窗口大小时更新窗口内部高度(Update window innerheight when resizing window)

编程入门 行业动态 更新时间:2024-10-28 20:31:27
调整窗口大小时更新窗口内部高度(Update window innerheight when resizing window)

到目前为止,我已经成功地使Id具有与窗口相同的innerHeight。 但是,当我调整窗口大小时,高度保持不变。

任何人都可以帮助我使Id与调整窗口时的内部高度相同吗? 这是代码

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

This far i have succeded to make an Id to have same innerHeight as the window. However when i resize the window the height stays the same.

Could anyone help me make the Id be the same innerHeight as the window whenever it is resized ? Here is the code

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'; });

this approach might play nicer with existing event handlers:

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

更多推荐

Id,height,innerHeight,window,窗口,电脑培训,计算机培训,IT培训"/> <meta name=&qu

本文发布于:2023-07-04 16:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026827.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗口   高度   小时   Update   innerheight

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!