我需要在网页浏览器中获得整个可用空间的高度,这样我就可以在屏幕的一半处定位一个div,并将其向下延伸。
我原以为document.body.clientHeight会起作用,但它返回了占用的空间,而不是可用的全部空间。
我还试着为每件事做一个“包装器”div:
<div id="wrapper" style="height: 100%; width: 100%;">
//my other code
</div>得到它的高度,但它仍然返回占用的空间。
如何使用Javascript或jQuery在web浏览器中获得总可用空间?
发布于 2013-02-13 13:58:43
来自jQuery文档高度()
This method is also able to find the height of the window and document.
$(window).height(); // returns height of browser viewport
$(document).height(); // returns height of HTML document发布于 2013-02-13 14:32:41
我是说元素的父元素中可用的空间,你可以试试这个.
var entireHeight=$('#elementID').parent().height();
var siblingHeight=0;
var elementSiblings=$('#elementID').siblings();
$.each(elementSiblings, function() {
siblingHeight= siblingHeight+$(this).height();
});减去值,即
(entireHeight-siblingHeight) 应该给你可用的空间。
希望能帮上忙..。)告诉我它是否不起作用。
发布于 2019-04-14 22:47:12
是非常简单的
max_height=screen.availHeight - (window.outerHight - window.innerHight)
https://stackoverflow.com/questions/14855223
复制相似问题