2

enter image description here

How can i get the height of overflowed part in my document.

Example: I resized the window and scrollbar appear, how can i obtain the height of the part that is out of the window.

Thanks in advance.

4

2 回答 2

6

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

$(document).height() - $(window).height()
于 2013-07-07T18:39:25.257 回答
0

The basic equation here is

documentHeight == windowHeight + scrollTop + scrollBottom

~

scrollBottom == documentHeight - windowHeight - scrollTop

With basic javascript (works with IE7 and above):

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 (fullscreen, can be tested in old browsers)

In jQuery it's even simpler:

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

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

于 2013-07-08T10:01:55.977 回答