Home > Web Front-end > JS Tutorial > body text

Summary of jQuery methods for getting page width and height

php中世界最好的语言
Release: 2018-04-23 17:36:00
Original
2063 people have browsed it

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();
Copy after login

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

$(window).width();
Copy after login

Get the document height of the page

$(document).height();
Copy after login

Get the document width of the page:

$(document).width();
Copy after login

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

$(document.body).height();
Copy after login

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

$(document.body).width();
Copy after login

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();
Copy after login

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

$(document).scrollLeft();
Copy after login

Get Or set the width of the element:

$(obj).width();
Copy after login

Get or set the height of the element:

$(obj).height();
Copy after login

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