Home > Web Front-end > JS Tutorial > jQuery gets a summary of page and element height and width - super practical_jquery

jQuery gets a summary of page and element height and width - super practical_jquery

WBOY
Release: 2016-05-16 15:48:31
Original
1248 people have browsed it

The following is a summary of jQuery’s methods of obtaining the height and width of pages and individual elements and is shared with everyone.

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

Copy code The code is as follows:

$(window).height();

Get the width of the browser display area (visual area):
Copy code The code is as follows:

$(window).width();

Get the document height of the page
Copy code The code is as follows:

$(document).height();

Get the document width of the page:
Copy code The code is as follows:

$(document).width();

The height of the document body of the current browser window:
Copy code The code is as follows:

$(document.body).height();

The width of the document body of the current browser window:

Copy code The code is as follows:

$(document.body).width();

Get the vertical height of the scroll bar to the top (that is, the height of the web page being scrolled up)
Copy code The code is as follows:

$(document).scrollTop();

Get the vertical width of the scroll bar to the left:
Copy code The code is as follows:

$(document).scrollLeft();

Get or set the width of the element:

Copy code The code is as follows:

$(obj).width();

Get or set the height of an element:
Copy code The code is as follows:

$(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 scroll bars)
The distance from the left edge of an element to the leftmost position of body: obj.offset().left; (when the containing element does not contain a scroll bar)
Returns the offset from the upper edge of the current element to the upper edge of its containing element: obj.offset().top (in the case where 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 (in the case where the element's containing element contains a scroll bar)
obj.offset().top;
Sets or returns the number of pixels that have been scrolled to the left or top edge of the element. 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 tags of the document (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