JS and jquery get page size, scroll bar position, element position

Source: Internet
Author: User
Tags relative

  This article is mainly about JS and jquery get page size, scroll bar position, element location sample code is introduced. Need friends can come to the reference, I hope to help you.

JS and jquery get page size, scroll bar position, element position     code as follows://page position and window size   function getpagesize () {var scrw, scrh;  if window . Innerheight && Window.scrollmaxy)   {   //Mozilla     SCRW = window.innerwidth + windows . Scrollmaxx;     SCRH = window.innerheight + window.scrollmaxy; }  else if (Document.body.scrollHeight > Docume Nt.body.offsetHeight) {   //all but IE Mac     SCRW = document.body.scrollWidth;     SCRH = document.body.scrollheight; } else if (document.body)   {//IE Mac     SCRW = Document.body.offsetWi Dth     SCRH = document.body.offsetHeight; }  var winw, winh;  if (window.innerheight)   {/All except IE     WINW = window.innerwidth;&nbsp ; 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 Vie wport  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.scroll Top;     x = document.documentelement.scrollleft; } else if (document.body) {   //all other IE &nbsp ;   y = Document.bodY.scrolltop;     x = Document.body.scrollLeft;   }  return {x:x, y:y};  }     jquery   Get the height of the browser display area: $ (window). Height ();  Gets the width of the browser display area: $ (window). Width ();  get page File Height: $ (document). Height ();  Gets the document width of the page: $ (document). width ();   Get 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 ();    Calculating the element position and offset   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 relative to the calculated offset position. This element should be relative or absolute positioned. The omission is relative to the body.   Options.scroll Whether the scroll bar is counted, the default true  options.padding whether the padding is counted, the default false  options.margin whether the margin meter Included, the default true  options.border whether the border is counted, default 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.