我试过了:
$(document).height();
$("#body").height();
但它没有给出确切的值。
答案 0 :(得分:0)
您正在寻找滚动高度属性
var el = document.body;
console.log(el.scrollHeight); // height with overflow
body {
height: 100vh;
}
.div {
height: 10000px;
}
<div class="div">
</div>
答案 1 :(得分:-1)
查看height function的规格:
// Returns height of browser viewport
$( window ).height();
// Returns height of HTML document
$( document ).height();
“整个页面的高度”我将其解释为viewport的大小。如果你正在寻找一些更强大的东西......
function getPageHeight ()
{
//If the content is smaller than the viewport, return the height
//of the screen. Otherwise, return the height of the content.
return Math.max ($(window).height (), $('body').height ());
}