Home  >  Article  >  Web Front-end  >  jQuery窗口、文档、网页各种高度的精确理解_jquery

jQuery窗口、文档、网页各种高度的精确理解_jquery

WBOY
WBOYOriginal
2016-05-16 16:42:42957browse

$(document).height():整个网页的高度
$(window).height():浏览器可视窗口的高度
$(window).scrollTop():浏览器可视窗口顶端距离网页顶端的高度(垂直偏移)

用一句话理解就是:当网页滚动条拉到最低端时,$(document).height() == $(window).height() + $(window).scrollTop()。

当网页高度不足浏览器窗口时$(document).height()返回的是$(window).height()。

不建议使用$("html").height()、$("body").height()这样的高度。

原因:

$("body").height():body可能会有边框,获取的高度会比$(document).height()小;
$("html").height():在不同的浏览器上获取的高度的意义会有差异,说白了就是浏览器不兼容。
$(window).height()值有问题,返回的不是浏览器窗口的高度?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn