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

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

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,732
    John Bokma
    Mar 18, 2006
  2. Kevin Spencer

    Re: Class property misunderstanding

    Kevin Spencer, Jun 26, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    986
    Kevin Spencer
    Jun 26, 2003
  3. Max
    Replies:
    1
    Views:
    642
    Joe Kesselman
    Sep 22, 2006
  4. P4trykx
    Replies:
    2
    Views:
    2,108
    bruce barker
    Jan 31, 2007
  5. james_027

    class attributes & data attributes

    james_027, Jun 20, 2007, in forum: Python
    Replies:
    2
    Views:
    620
    Bruno Desthuilliers
    Jun 20, 2007
  6. Barak, Ron

    Basic misunderstanding of generators

    Barak, Ron, Dec 22, 2008, in forum: Python
    Replies:
    0
    Views:
    267
    Barak, Ron
    Dec 22, 2008
  7. Kyle Schmitt
    Replies:
    3
    Views:
    419
    Kyle Schmitt
    Jul 24, 2007
  8. Jayden
    Replies:
    16
    Views:
    805
    Steven D'Aprano
    Sep 29, 2012
Loading...