spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column29


Window and Page Scrolling Functions

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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 window's width: The physical width of the browser window in pixels.
  • The window's height: The physical height of the browser window in pixels.
  • The page's right-scrolled portion: The size of the scrolled right portion of the page to the right. This is the distance in pixels between the left edge of window to the left edge of the page.
  • The page's down-scrolled portion. The size of the scrolled down portion of the page. This is the distance in pixels between the top edge of the window to the top edge of the page.

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

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


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

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