[Javascript] How to set the scrolling of a div

Bernu Bernard bernu at lptmc.jussieu.fr
Fri Jan 12 09:53:14 CST 2007


Hi list,

I have a container div with heigth:100px and overflow:auto
Inside I have a div with a height:200px. Thus the container div has a  
vertical scrollbar.

I tried without success scrollBy and scrollTo : div does not  
understand these functions

What should I do so that the inner-div scroll by 50px.

Bernard
This is a simple example :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns = "http://www.w3.org/1999/xhtml"  >
	<head>
		<title>test scroll bar</title>
<script type="text/javascript"><!--

function scrolldiv( ) {
	var x = document.getElementById( "div1" )
	x.scrollBy( 10, 10 ) ;
	alert("ok");
}

--></script>
	</head>
	<body onload="scrolldiv( ) ">
		<div id="div1" style="height:100px; border:solid 10px #00f ;  
overflow:auto">
			<div id="div2" style="height:200px; background: #fee; border:solid  
10px #0f0"></div>
		</div>
	</body>
</html>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20070112/940b7170/attachment.htm>


More information about the Javascript mailing list