[thelist] pushing scrollbar to bottom

Christian Heilmann codepo8 at gmail.com
Wed Oct 19 08:45:46 CDT 2005


> > Im trying to work out how to push the scroll bar to the
> > bottom of a long
> > bit of text, say more than 1 page long. equivalent of
> > pressing the ctrl
> > + end buttons
> >
> > is it scriptable? tried vertical align: bottom but no joy
> >
>
> I've done something like this before:
>
>      <script>
>       function log(str)
>       {
>         var console = document.getElementById("console");
>         if(console)
>         {
>           console.value += str + '\n';
>           console.scrollTop = console.scrollHeight - console.clientHeight;
>         }
>       }
>
>       setInterval("log(Math.random());", 500);
>     </script>
>   <body>
>     <textarea id="console" rows="10"></textarea>
>   </body>
>
>
> Not all browsers have the scrollTop, scrollHeight & clientHeight properties,
> depends on your requirements.  Works in IE & Firefox.  This example is
> controlling the scrollbar on a textarea, but it should work for any
> scrollable element.

Ouh, this looks like it leaks memory by the truckload. If you need to
use intervals, also make sure you give them a name and clear them
again.

--
Chris Heilmann
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/
Binaries: http://www.onlinetools.org/


More information about the thelist mailing list