Javascript and Jq methods for getting browser and object values _ javascript skills

Source: Internet
Author: User
This article mainly introduces information about how to use Js and Jq to obtain the browser and object values. For details about how to use JS and Jquery to obtain the width of page elements, what are the differences between height, relative displacement, and other values that can be converted or replaced by each other? This article will introduce you in detail.

1. Js get the browser height and width

Document.doc umentElement. clientWidth ==> visible area width of the browser
Document.doc umentElement. clientHeight => visible area height of the browser
Document. body. clientWidth ==> BODY object width
Document. body. clientHeight ==> BODY object height

Jq obtains the browser height and width.

$ (Window). width () ==> visible area width of the browser
$ (Window). height () ==> visible area height of the browser
$ (Document). height () ==> height of the page document
$ (Document. body). height () ==> BODY object height

2. Js get the object height and width

Obj. width = obj. style. width
Obj. clientWidth = width + padding => get the element width including the inner border (padding)
Obj. offsetHeight = height + padding + border => get the element height including the inner border (padding) and border (border)

Jq obtains the height and width of an object.

Obj. innerWidth () ==> get the element width including the inner boundary (padding,
Obj. outerWidth () ==> get the element width including the inner border (padding) and border (border)
Obj. outerWidth (true) ==> get the element width including the outer border (margin)

W the same element should be: width () <= innerWidth () <= outerWidth (true );

3. Js get the relative height and width of the object

Obj. offsetLeft ==> left of the element relative to the parent Element
Obj. offsettop ==> top of the element relative to the parent Element
Obj. scrollWidth => get the scroll width of an object
Obj. scrollHeight => get the scroll height of an object
Obj. scrollLeft ==> sets or obtains the distance between the left-side scrolling of the object.
Obj. scrollTop ==> set or obtain the scroll distance at the top of the object

Jq obtains the relative height and width of an object.

Obj. offset (). left ==> element relative to left of the document
Obj. offset (). top ==> the element is relative to the top of the document
Obj. scrollLeft () ==> set or return the offset of the object to the left of the scroll bar.
Obj. scrollTop () ==> set or return the offset of the object relative to the top of the scroll bar.

The above section describes how to use Js and Jq to obtain the browser and object values. I hope this will help you!

Related Article

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.