如何在文档中获得溢出部分的高度。
示例:我调整了窗口大小并显示滚动条,如何获得窗口外部分的高度。
提前致谢。
答案 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/show(全屏,可在旧浏览器中测试)
在jQuery中它甚至更简单:
var winH = $(window).height();
var docH = $(document).height();
var scrollTop = $(window).scrollTop();
var scrollBottom = docH - winH - scrollTop;