如何获得整个可用空间的高度?

Doo*_*nob 2 html javascript jquery

我需要在网络浏览器中获得整个可用空间的高度,这样我就可以div在屏幕中间放置一半并将其一直向下拉伸.

我认为document.body.clientHeight会起作用,但这会带来正在占用的空间量,而不是总的可用空间.

我也试过div围绕一切做一个"包装" :

<div id="wrapper" style="height: 100%; width: 100%;">
    //my other code
</div>
Run Code Online (Sandbox Code Playgroud)

并获得高度,但仍然会占用空间.

如何使用Javascript或jQuery获取Web浏览器中的总可用空间?

epa*_*llo 5

来自jQuery docs height()

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
Run Code Online (Sandbox Code Playgroud)