JS and jquery get page size, scroll bar position, element position
Copy Code code as follows:
//Page position and window size
function GetPageSize () {
var scrw, SCRH;
if (window.innerheight && window.scrollmaxy)
{//Mozilla
SCRW = window.innerwidth + Window.scrollmaxx;
SCRH = Window.innerheight + window.scrollmaxy;
}
else if (Document.body.scrollHeight > Document.body.offsetHeight)
{//all but IE Mac
SCRW = Document.body.scrollWidth;
SCRH = Document.body.scrollHeight;
else if (document.body)
{//IE Mac
SCRW = Document.body.offsetWidth;
SCRH = Document.body.offsetHeight;
}
var winw, Winh;
if (window.innerheight)
{//All except IE
WINW = window.innerwidth;
Winh = Window.innerheight;
else if (document.documentelement && document.documentElement.clientHeight)
{//IE 6 Strict Mode
WINW = Document.documentElement.clientWidth;
Winh = Document.documentElement.clientHeight;
else if (document.body) {//other
WINW = Document.body.clientWidth;
Winh = Document.body.clientHeight;
}//For small pages and total size less then the viewport
var Pagew = (SCRW<WINW)? WINW:SCRW;
var Pageh = (Scrh<winh)? WINH:SCRH;
return {Pagew:pagew, Pageh:pageh, WINW:WINW, Winh:winh};
};
scroll bar position
function Getpagescroll ()
{
var x, y; if (Window.pageyoffset)
{//All except IE
y = Window.pageyoffset;
x = Window.pagexoffset;
else if (document.documentelement && document.documentElement.scrollTop)
{//IE 6 Strict
y = Document.documentElement.scrollTop;
x = Document.documentElement.scrollLeft;
else if (document.body) {//All other IE
y = Document.body.scrollTop;
x = Document.body.scrollLeft;
}
return {x:x, y:y};
}
jquery
Gets the height of the browser display area: $ (window). Height ();
Gets the width of the browser display area: $ (window). width ();
Gets the document height of the page: $ (document). Height ();
Gets the document width of the page: $ (document). width ();
Gets the vertical height of the scroll bar to the top: $ (document). ScrollTop ();
Gets the vertical width of the scroll bar to the left: $ (document). ScrollLeft ();
Calculate element position and offset
The offset method is a useful way to return the offset information for the first element in the wrapper set. By default, the offset information for the body is relative. The result contains top and left two properties.
Offset (options, results)
Options.relativeto Specifies the ancestor element that calculates the offset position relative to the calculation. This element should be relative or absolute positioned. The omission is relative to the body.
Options.scroll whether scroll bars are counted, default true
Options.padding whether the padding is counted, the default false
Options.margin whether the margin is counted, default true
Options.border whether the border is counted, default true