我正在寻找一种在 javascript 中计算浏览器大小的方法 (px)
然后计算一个<div>
的大小带走50px
从那个全屏尺寸:
例如
Browser screen size: 800px (Height)
Existing <div> that is always 50px (Height)
Leaves 750px (Height) for the remaining <div> to fill the page.
然后拿那个750px
并将其应用为内联样式:
<div style="height: 50px">
<img src="banner.png" />
</div>
<div style="height: x">
This fills the remainder of the page
</div>
最佳答案
我假设您指的是文档高度,而不是浏览器高度。您可以使用类似以下的方法执行此操作:
$("#div2").height($(document).height() - 50);
// or for more dynamicity
$("#div2").height($(document).height() - $("#div1").height());
如果您指的是浏览器高度而不是文档高度,请将 $(document)
替换为 $(window)
。
关于Javascript/jQuery 高度计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2720105/