/* thanks to PPK - http://www.quirksmode.org/viewport/compatibility.html */ function Viewport_Class () {}; Viewport_Class.prototype.getWindowSize = function() { // returns innerHeight / innerWidth of window if (self.innerHeight) { // all except Explorer var width = self.innerWidth; var height = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode var width = document.documentElement.clientWidth; var height = document.documentElement.clientHeight; } else if (document.body) { // other Explorers var width = document.body.clientWidth; var height = document.body.clientHeight; }; return { width: width, height: height }; }; Viewport_Class.prototype.getWindowScrollOffset = function() { // returns window's scroll offset if (typeof window.pageYOffset == 'number') { //Netscape compliant var x = window.pageXOffset; var y = window.pageYOffset; } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) { //DOM compliant var x = document.body.scrollLeft; var y = document.body.scrollTop; } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) { //IE6 standards compliant mode var x = document.documentElement.scrollLeft; var y = document.documentElement.scrollTop; }; return { x: x||0, y: y||0 }; }; Viewport_Class.prototype.get = function() { // returns viewport boundaries and dimensions as top, left, bottom, right, height, width var windowSize = this.getWindowSize(); var scrollOffset = this.getWindowScrollOffset(); var top = scrollOffset.y; var bottom = scrollOffset.y + windowSize.height; var left = scrollOffset.x; var right = scrollOffset.x + windowSize.width; return { top: top, left: left, bottom: bottom, right: right, width: windowSize.width, height: windowSize.height }; }; WSDOM.defineClass("Viewport", null, Viewport_Class); WSDOM.loadSingleton("WSDOM.Viewport.1");