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 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}
}
Created: November 9, 1998
Revised: November 9, 1998
URL: https://www.webreference.com/js/column29/window.html