Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   How to set a scrollbar value (http://www.velocityreviews.com/forums/t935369-how-to-set-a-scrollbar-value.html)

joe 04-05-2008 09:28 AM

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).

Joost Diepenmaat 04-05-2008 10:19 AM

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/

joe 04-06-2008 04:22 PM

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

Joost Diepenmaat 04-06-2008 04:37 PM

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/

joe 04-07-2008 06:23 AM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57