当前位置:首页 > Windows程序 > 正文

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

2021-03-16 Windows程序

前言:在此以高度为示例,宽度问题可类推。在移动端开发中,经常遇到需要把一块内容定位于底部的情况,当页面内容不满一屏时,需要设为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的前提。

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

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/61926.html