![]() |
How to set a scrollbar value
I have a div like this:
<div id="myDiv" style="width:200; height:200; overflow:scroll;"> How do I manually set the initial vertical scrollbar position? The div has several hundreds of lines of text and I'd like to start at a certain position (not necessaryly text line). |
Re: How to set a scrollbar value
joe <mt@invalid.com> writes:
> I have a div like this: > > <div id="myDiv" style="width:200; height:200; overflow:scroll;"> > > How do I manually set the initial vertical scrollbar position? > > The div has several hundreds of lines of text and I'd like to start at a certain > position (not necessaryly text line). You can set the scrollLeft and scrollTop attributes from a script. -- Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/ |
Re: How to set a scrollbar value
Joost Diepenmaat <joost@zeekat.nl> wrote:
>joe <mt@invalid.com> writes: > >> I have a div like this: >> >> <div id="myDiv" style="width:200; height:200; overflow:scroll;"> >> >> How do I manually set the initial vertical scrollbar position? >> >> The div has several hundreds of lines of text and I'd like to start at a certain >> position (not necessaryly text line). > >You can set the scrollLeft and scrollTop attributes from a script. Thanks. I tied it and it works fine in IE but not in Firefox. My code is like this: document.write('<div id="myDiv" style="width:2 ...blah blah ....some code document.write('</div>'); document.getElementById('myDiv').scrollTop=650; //error here in Firefox, IE OK |
Re: How to set a scrollbar value
joe <mt@invalid.com> writes:
> My code is like this: > > document.write('<div id="myDiv" style="width:2 ...blah blah > ...some code > document.write('</div>'); > document.getElementById('myDiv').scrollTop=650; //error here in Firefox, IE OK What error? You can't in general count on getElementById() working before the whole DOM is rendered. The easiest way to to work around that is to do your document.getElementById('myDiv').scrollTop=650 call from a onload handler. -- Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/ |
Re: How to set a scrollbar value
Joost Diepenmaat <joost@zeekat.nl> wrote:
>joe <mt@invalid.com> writes: > > >> My code is like this: >> >> document.write('<div id="myDiv" style="width:2 ...blah blah >> ...some code >> document.write('</div>'); >> document.getElementById('myDiv').scrollTop=650; //error here in Firefox, IE OK > >What error? The div is not scrolled and code running stops. > >You can't in general count on getElementById() working before the whole >DOM is rendered. The easiest way to to work around that is to do your >document.getElementById('myDiv').scrollTop=650 call from a onload handler. OK. Works now. Thanks. |
| All times are GMT. The time now is 01:53 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.