当前位置: 动力学知识库 > 问答 > 编程问答 >

Overflowed height - jQuery

问题描述:

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.

网友答案:

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/

网友答案:

The height of the document (all content) less the height of the viewport.

$(document).height() - $(window).height()
分享给朋友:
您可能感兴趣的文章:
随机阅读: