[Javascript] Emulate position:fixed in IE

Roger Roelofs rer at datacompusa.com
Thu Sep 4 11:11:20 CDT 2003


I'm working on a script that will allow ie to kind of emulate the css 
position:fixed; css attribute.  (Code follows)  My problem is figuring 
out the height of the _content_ of the div, rather than the height of 
the div itself.  Currently my script doesn't function properly if you 
resize your browser window to make it larger.

function pretendFixed() {
	if ((typeof(el.nodeType) != "undefined") && (el.nodeType == 1)) {
		var winHeight = 0;
		if (typeof(window.innerHeight) == 'number') {
			winHeight = window.innerHeight;
		} else {
			if (document.documentElement &&
				document.documentElement.clientHeight) {
				winHeight = document.documentElement.clientHeight;		
			} else {
				if (document.body && document.body.clientHeight) {
					winHeight = document.body.clientHeight;
				}
			}
		}
		var newElHeight = el.offsetHeight;
		if (winHeight < (el.offsetTop + el.offsetHeight)) {
			newElHeight = winHeight - (el.offsetTop + 10);
			if (el.style) {
				el.style.height = newElHeight + "px";
				el.style.overflow = "scroll";
			}
		}
	}
}




More information about the Javascript mailing list