Home > Web Front-end > HTML Tutorial > Differences and connections between $(document).height(), $('body').height(), $(window).height()

Differences and connections between $(document).height(), $('body').height(), $(window).height()

WBOY
Release: 2016-07-21 14:53:04
Original
1445 people have browsed it

Foreword: Here we take height as an example, and the width issue can be analogized. In mobile development, we often encounter situations where a piece of content needs to be positioned at the bottom. When the page content is less than one screen, it needs to be set to fixed. When it exceeds one screen, it needs to be set to static and the page will be pushed to the bottom. At this time You need to determine whether the content exceeds the screen by judging the size of $(document).height() and $(window).height().

$(document): Entire document
$("body"):body
$(window): Viewport (provided doctype is set)

1) When the page content is larger than the viewport (browser window): $(document).height() = $("body").height() > $(window).height();

2) When the page content is smaller than the viewport: $(document).height() = $(window).height() > $("body").height();

In addition: $(window).height() is also affected by the DOCTYPE of the page header, and the default is the premise of DOCTYPE.

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template