Basic misunderstanding of attributes

Discussion in 'HTML' started by Chris, Mar 2, 2004.

  1. Chris

    Chris Guest

    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.
    Chris, Mar 2, 2004
    #1
    1. Advertising

  2. Chris wrote:
    > 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.

    <snip>
    > 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.
    Leif K-Brooks, Mar 2, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Hobley

    vec - a misunderstanding

    Mark Hobley, Mar 18, 2006, in forum: Perl
    Replies:
    1
    Views:
    2,600
    John Bokma
    Mar 18, 2006
  2. Kevin Spencer

    Re: Class property misunderstanding

    Kevin Spencer, Jun 26, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    824
    Kevin Spencer
    Jun 26, 2003
  3. Philip Tripp

    View State Misunderstanding

    Philip Tripp, Jul 24, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    518
    Philip Tripp
    Jul 26, 2004
  4. Shawn Wildermuth

    Misunderstanding ConnectionStrings?

    Shawn Wildermuth, Jan 9, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    1,909
    Steven Cheng[MSFT]
    Jan 11, 2006
  5. Barak, Ron

    Basic misunderstanding of generators

    Barak, Ron, Dec 22, 2008, in forum: Python
    Replies:
    0
    Views:
    228
    Barak, Ron
    Dec 22, 2008
Loading...

Share This Page