Basic misunderstanding of attributes

C

Chris

I'm trying to display a large amount of text in a scrolling DIV. I want the
scrollbar positioned at the bottom when the page is first displayed. My
DHTML reference suggests this can be done using the scrollTop property. I
just can't figure out how to use it.

These three attempts didn't work:

<div scrollTop=1000>block of text</div>

<div style="scrollTop : 1000">block of text</div>

<div id="log">block of text</div>
<script>
document.getElementById("log").scrollTop=1000;
</script>

This is the only thing that *does* work, but I have to click a link to get
it to go:

<div id="log">block of text</div>
<script>
function scroll() {
document.getElementById("log").scrollTop=1000;
}
</script>
<a href="javascript:scroll()">click here</a>

There's got to be some simple syntax that I'm missing.
 
L

Leif K-Brooks

Chris said:
I'm trying to display a large amount of text in a scrolling DIV. I want the
scrollbar positioned at the bottom when the page is first displayed. My
DHTML reference suggests this can be done using the scrollTop property. I
just can't figure out how to use it.
There's got to be some simple syntax that I'm missing.

Put this in your head element:
<script type="text/javascript" src="scrolltop.js"></script>

And this in scrolltop.js:
function setScrollTop() {
var element = document.getElementById('foo');
element.scrollTop = 100;
}
window.onload = setScrollTop;


But note that scrollTop is nonstandard, scrollTop won't work the same
because of text sizes (scrollTop is in pixels), and users may be
confused by documents scrolling on their own.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top