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!