有滚动条时如何获得全窗口高度?

时间:2014-01-30 11:17:31

标签: jquery

var window_height = $(window).height();这使得当前窗口高度不是包括滚动高度在内的整个高度。我想要完整的窗口高度,包括滚动高度。

6 个答案:

答案 0 :(得分:7)

你应该检查这个链接: How to get height of entire document with JavaScript?

    var body = document.body,
    html = document.documentElement;

var height = Math.max( body.scrollHeight, body.offsetHeight, 
                       html.clientHeight, html.scrollHeight, html.offsetHeight );

答案 1 :(得分:3)

截至2020年,查找整个文档高度的最佳方法是:

document.documentElement.scrollHeight

信用:this answer关于另一个问题。

答案 2 :(得分:1)

是的,这是

$("body").height()

答案 3 :(得分:1)

使用$(document).height();以获得可滚动区域的全高。

使用$(window).height();仅获得可见区域的高度。

重要提示:文档的高度是整个文档的整个高度,即使在可见区域之外。 窗口的高度只是可见区域。

答案 4 :(得分:0)

使用:

function getheight(){
    var d= document.documentElement;
    var b= document.body;
    var who= d.offsetHeight? d: b ;
    return Math.max(who.scrollHeight,who.offsetHeight);
}
getheight()

答案 5 :(得分:0)

以上都不适合我 - 都给了视口高度。我必须将整个页面包装在一个div(class' wrapper')中,然后使用:

    $('.wrapper').prop('scrollHeight');
相关问题