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.
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.
文档(所有内容)的高度减去视口的高度。
$(document).height() - $(window).height()
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/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;