溢出的高度 - jQuery

时间:2013-07-07 18:36:08

标签: jquery

enter image description here

如何在文档中获得溢出部分的高度。

示例:我调整了窗口大小并显示滚动条,如何获得窗口外部分的高度。

提前致谢。

2 个答案:

答案 0 :(得分:6)

文档的高度(所有内容)减去视口的高度。

$(document).height() - $(window).height()

答案 1 :(得分:0)

这里的基本等式是

documentHeight == windowHeight + scrollTop + scrollBottom

~

scrollBottom == documentHeight - windowHeight - scrollTop

使用基本的javascript(适用于IE7及以上版本):

var winH = document.documentElement.clientHeight;
var docH = document.body.clientHeight;
var scrollTop = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
var scrollBottom = docH - winH - scrollTop;

http://jsfiddle.net/QTHuL/

http://jsfiddle.net/QTHuL/show(全屏,可在旧浏览器中测试)

在jQuery中它甚至更简单:

var winH = $(window).height();
var docH = $(document).height();
var scrollTop = $(window).scrollTop();
var scrollBottom = docH - winH - scrollTop;

http://jsfiddle.net/QTHuL/1/