[thelist] Javascript for 'to top' if page is long, otherwise not

VOLKAN ÖZÇELİK volkan.ozcelik at gmail.com
Fri Nov 18 13:09:47 CST 2005


The below shall work in all modern browsers -- not tested.

step 1:
-----------------------------------------------------
get window height:

var height=-1;
	
if (self.innerHeight){/*all except ie*/
	height=self.innerHeight;
}
else if(document.documentElement&&document.documentElement.clientHeight){
	/*ie strict*/
	height=document.documentElement.clientHeight;
}
else if (document.body){
	/*last trial*/
	height=document.body.clientHeight;
}


step 2:
-----------------------------------------------------
get container height:

containerHeight = document.getElementById("MainContent").offsetHeight;

step 3:
-----------------------------------------------------
compare them and act:

var diff=height-containerHeight;

if(diff<0){
	document.getElementById("LinkToTop").style.visibility="visible";
}
else {
	document.getElementById("LinkToTop").style.visibility="hidden";
}

HTH,
--
Volkan Ozcelik
+>Yep! I'm blogging! : http://www.volkanozcelik.com/volkanozcelik/blog/
+> My projects/studies/trials/errors : http://www.sarmal.com/



More information about the thelist mailing list