This article mainly introduces how jquery can obtain the height of the element's scroll bar and other implementation code. If you need it, refer to the following main functions:
Get the height of the browser display area (visible area): $ (window ). height (); get the width of the browser display area (visible area): $ (window ). width (); get the document height of the page $ (document ). height (); get the document width of the page: $ (document ). width (); the height of the current file body in the browser window: $ (document. body ). height (); the width of the current file body in the browser: $ (document. body ). width (); get the vertical height of the scroll bar to the top (that is, the height of the page being rolled up) $ (document ). scrollTop (); gets the vertical width of the scroll bar to the left: $ (document ). scrollLeft (); get or set the width of the element: $ (obj ). width (); get or set the height of an element: $ (obj ). height (); the distance from the upper boundary of an element to the top of the body: obj. offset (). top; (when an element contains an element that does not contain a scroll bar) the leftmost distance from the left boundary of an element to the body: obj. offset (). left; (if the element that contains the element does not contain the scroll bar) returns the offset from the upper boundary of the current element to the upper boundary of the element that contains the element: obj. offset (). top (when an element contains a scroll bar) returns the offset from the left boundary of the current element to its left boundary containing the element: obj. offset (). left (when an element contains a scroll bar)
// Return the current page height function pageHeight () {if ($. browser. msie) {return document. compatMode = "CSS1Compat "? Document.doc umentElement. clientHeight: document. body. clientHeight;} else {return self. innerHeight ;}}; // returns the current page Width function pageWidth () {if ($. browser. msie) {return document. compatMode = "CSS1Compat "? Document.doc umentElement. clientWidth: document. body. clientWidth;} else {return self. innerWidth ;}};
The following is a supplement from other netizens:
Get 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 on the page: $ (document). height ();
Get the document width: $ (document). width ();
Obtain the vertical height of the scroll bar to the top: $ (document). scrollTop ();
Obtain the vertical width of 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.
Child page control parent page:
Parent.document.doc umentElement. scrollTop;
Parent.document.doc umentElement. clientHeight;