JQuery obtains the page width, scroll bar height, and element height.

Source: Internet
Author: User

JQuery gets the page width, the scroll bar height, and the element height. We only need to sort these functions to implement the functions we want. Let's take a look at them.


Jquery retrieves the scroll bar height

Obtain the height of the display area of the browser:

$ (Window). height ();

Obtain the width of the display area of the browser:

$ (Window). width ();
Get the document height of the page:
$ (Document). height ();
Get the document width: $ (document). width ();

Obtain the vertical height from the scroll bar to the top:

$ (Document). scrollTop ();

Obtain the vertical width from the scroll bar to the left:

$ (Document). scrollLeft ();

Calculate the element position and offset:

$ (Id). offset ();

The offset method is a useful method that returns the offset information of the first element in the packaging set. By default, it is the offset information relative to the body. The result contains the top and left attributes.

Offset (options, results)
Options. relativeTo
Calculates the ancestor element at the offset position. This element should be located by relative or absolute. If this parameter is omitted, it is relative to the body.
Options. Does scroll set
The scroll bar is included. The default value is TRUE.
Options. whether to include padding. The default value is false.
Options. margin

Whether to include margin. The default value is true.

Options. border determines whether to include the border. The default value is true.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.