Javascript Help

OT: anything goes!

Moderator: Edi

Post Reply
User avatar
Pu-239
Sith Marauder
Posts: 4727
Joined: 2002-10-21 08:44am
Location: Fake Virginia

Javascript Help

Post by Pu-239 »

I'm trying to emulate position:fixed in IE, but it's kinda jerky-

Code: Select all

var sidebar = getObj('sidebar');
function sidebarSize(){
	var height = getWinHeight()-12+'px';
	sidebar.style.height = height;
	sidebar.style.position = 'absolute';
}

function sidebarSticky(){
	sidebar.style.top = getScrollY()+6;
}

if(userAgent('IE')){
	sidebarSize();
	window.onresize = sidebarSize;
	window.onscroll = sidebarSticky;
}
getObj is merely an alias for document.getElementById or document.all, while getWinHeight returns the size of the viewport. How do I make it less jerky, or is it something I have to accept because of the slow speed of my computer? Can someone with a faster computer test it out using IE?


Heres the whole thing:

index.html:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	"http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
<title>Insert Title Here</title>
<link rel="stylesheet" href="style.css">
<style type="text/css">
<!--
#sidebar			{position:fixed;
						background-color:black;
						width:175px;
						height:auto;
						top:6px;bottom:6px;
						left:6px;margin:0px 0px;
						overflow:auto;}
body				{height:60em}
-->
</style>
<script type="text/javascript" src="./scripts/lib.js"></script>
</head>
<body>

<div id="sidebar">
</div>

<script type="text/javascript">
<!--
//use stylesheet if Moz and NS6+ and Opera are not as shitty as 
//M$'s IE. Box model in IE not implemented correctly

//Jerky scroll, but oh well. You should be using Mozilla anyways.
var sidebar = getObj('sidebar');

function sidebarSize(){
	var height = getWinHeight()-12+'px';
	sidebar.style.height = height;
	sidebar.style.position = 'absolute';
}
function sidebarSticky(){
	sidebar.style.top = getScrollY()+6;
}

if(userAgent('IE')){ 
	sidebarSize();
	window.onresize = sidebarSize;
	window.onscroll = sidebarSticky;
}

//-->
</script>
</body>
</html>
./scripts/lib.js, with irrelevant parts stripped out:

Code: Select all

function userAgent(UA){
	reUA = new RegExp(UA);
	return reUA.test(navigator.userAgent);
}

function getObj(objID){
	if(document.getElementById){
		return document.getElementById(objID);
	}else{
		return document.all[objID];
	}
}

function getWinHeight(){
	if((document.all && (document.compatMode == 'BackCompat'))||(!document.all)){//M$ Sucks!!!!!!
		return document.body.clientHeight; 
	}else{
		if(document.all){
			return document.documentElement.clientHeight;
		}
	}
}


function getScrollY(){
	if((document.all && (document.compatMode == 'BackCompat'))||(!document.all)){ //M$ Sucks!!!!!!
		return document.body.scrollTop; 
	}else{
		if(document.all){
			return document.documentElement.scrollTop;
		}
	}
}

ah.....the path to happiness is revision of dreams and not fulfillment... -SWPIGWANG
Sufficient Googling is indistinguishable from knowledge -somebody
Anything worth the cost of a missile, which can be located on the battlefield, will be shot at with missiles. If the US military is involved, then things, which are not worth the cost if a missile will also be shot at with missiles. -Sea Skimmer


George Bush makes freedom sound like a giant robot that breaks down a lot. -Darth Raptor
User avatar
Pu-239
Sith Marauder
Posts: 4727
Joined: 2002-10-21 08:44am
Location: Fake Virginia

Post by Pu-239 »

Well can someone at least test it?

ah.....the path to happiness is revision of dreams and not fulfillment... -SWPIGWANG
Sufficient Googling is indistinguishable from knowledge -somebody
Anything worth the cost of a missile, which can be located on the battlefield, will be shot at with missiles. If the US military is involved, then things, which are not worth the cost if a missile will also be shot at with missiles. -Sea Skimmer


George Bush makes freedom sound like a giant robot that breaks down a lot. -Darth Raptor
Post Reply