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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.