Introducing DOCJSLIB 3.0, Window and Page Scrolling Functions - Doc JavaScript | WebReference

Introducing DOCJSLIB 3.0, Window and Page Scrolling Functions - Doc JavaScript


Window and Page Scrolling Functions

DOCJSLIB Version 3.0 introduces four new functions that relate to the physical dimensions of the browser window and its relative position with respect to the top left corner of the page. These functions deal with four dimensions:

The getWindowWidth() function gets the window's width:

function docjslib_getWindowWidth() {
  if (NS4) {return window.innerWidth}
  else {return document.body.clientWidth}
}

Notice how Netscape Navigator stores the window width under the window object, while Internet Explorer stores it under the document.body object. Similarly, the getWindowHeight() function is defined as follows:

function docjslib_getWindowHeight() {
  if (NS4) {return window.innerHeight}
  else {return document.body.clientHeight}
}

The getPageScrollLeft() gets the size in pixels of the right-scrolled portion of the page:

function docjslib_getPageScrollLeft() {
  if (NS4) {return window.pageXOffset}
  else {return document.body.scrollLeft}
}

The matching getPageScroolTop() function gets the scrolled-down portion of the page:

function docjslib_getPageScrollTop() {
  if (NS4) {return window.pageYOffset}
  else {return document.body.scrollTop}
}

http://www.internet.com


Created: November 9, 1998
Revised: November 9, 1998

URL: http://www.webreference.com/js/column29/window.html