Maison >interface Web >tutoriel HTML >$(document).height()、$("body").height()、$(window).height()区别和联系

$(document).height()、$("body").height()、$(window).height()区别和联系

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBoriginal
2016-07-21 14:53:041506parcourir

前言:在此以高度为示例,宽度问题可类推。在移动端开发中,经常遇到需要把一块内容定位于底部的情况,当页面内容不满一屏时,需要设为fixed,而超过 一屏时,需要设为static随页面顶到底部,此时就需要通过判断$(document).height()和$(window).height()的大 小来区分内容是否超屏。

$(document):整个文档
$("body"):body
$(window):视口(有设doctype的前提下)

1)、页面内容大于视口(浏览器窗口)时:$(document).height() = $("body").height() > $(window).height();

2)、页面内容小于视口时:$(document).height() = $(window).height() > $("body").height();

另:$(window).height()还受页头DOCTYPE的影响,在此默认为有DOCTYPE的前提。

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent:浅析css布局模型2Article suivant:前端开发必备站点汇总