Jump to content

Scroll down but not the top row.


rline101

Recommended Posts

you could use css.

 

'position: fixed' is the bunny but it don't work in ie 6 or less (it decides to render as position: absolute instead);

 

The javaascript solution does exist as andy suggest...

 

here is my effort

keepVisible	=	function (id)
{
var	el				=	document.getElementById(id);
var	getScrollTop	=	function()
{
	return document.body.scrollTop||document.documentElement.scrollTop
};
el.keepInView	=	function()
{
	var target	=	getScrollTop();	
	var curY		=	el.offsetTop;

	var curY	=	el.offsetTop;
	var newY	=	null;
	newY	=	curY + ((target - curY)/20);
	newY	=	Math.ceil(newY);
	if	(
		newY	==	null
		)
	{
		newY	=	target;
	}
	el.style.top	=	newY + 'px';
}
setInterval('document.getElementById("' + id + '").keepInView()',10);
}

 

all you need is

 

	<script type="text/javascript">
		keepVisible('yourelement');
	</script>

directly after the element you want to keep at the top. (should be able to call it on the body onload attribute but I encountered a couple of browsers that didn't play ball)

 

The above will make you element 'glide' into view. If you want it to just shift immediately then simply set newY = target instead of the

 

newY = curY + ((target - curY)/20);

newY = Math.ceil(newY);

 

lines.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.