Home Web Front-end JS Tutorial Summary of jQuery methods for getting page width and height

Summary of jQuery methods for getting page width and height

Apr 23, 2018 pm 05:36 PM
jquery Summarize method

This time I will bring you a summary of the jQuery method of getting the page width and height. What are the precautions for jQuery to get the page width and height? Here are practical cases, let’s take a look.

Get the height of the browser display area (visual area):

$(window).height();

Get the width of the browser display area (visual area):

$(window).width();

Get the document height of the page

$(document).height();

Get the document width of the page:

$(document).width();

Height of the document body of the current window of the browser:

$(document.body).height();

Height of the document body of the current window of the browser Width:

$(document.body).width();

Get the vertical height of the scroll bar to the top (that is, the height of the web page when it is rolled up)

$(document).scrollTop();

Get the vertical width of the scroll bar to the left:

$(document).scrollLeft();

Get Or set the width of the element:

$(obj).width();

Get or set the height of the element:

$(obj).height();

The distance from the upper border of an element to the top of body: obj .offset().top; (When the containing element does not contain a scroll bar)
The distance from the left border of an element to the leftmost edge of body: obj .offset().left; (When the element's containing element does not contain a scroll bar)
Returns the offset from the upper boundary of the current element to the upper boundary of its containing element: obj .offset().top(When the element's containing element contains a scroll bar)
Returns the offset from the left edge of the current element to the left edge of its containing element: obj.offset ().left (When the containing element of the element contains a scroll bar)
obj.offset().top;
Set or return the left boundary of the element that has been scrolled Or the number of pixels of the upper boundary. Simply put, it is to set or get the offset of the matching element relative to the upper or left side of the scroll bar. These pixels are only useful if the element has scrollbars, for example, if the element's CSS overflow property is set to auto. These properties are also only defined on the or tag (this depends on the browser), and together they are used to specify the position of the scrolling document. Note that these properties do not specify the amount of scrolling for an