Results 1 to 4 of 4

Thread: Can't figure out a way to auto-scroll to a certain point within a div.

  1. #1
    Join Date
    Oct 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can't figure out a way to auto-scroll to a certain point within a div.

    I'm not quite sure how I would go about doing this. I've searched for ways to scroll to a point within a div, but I've only been able to find methods for doing this within the window (and not the div).

    Does anyone know how to auto-scroll to a certain point within a div? And when I say auto-scroll, I mean like smooth scrolling.

    Here's the code I have right now. I just don't know what to add to it.

    Code:
    <script type="text/javascript">
    
    var t;
    var doLoop = true;
    
    function scrollDivToTop(divid)
    {
    var div = document.getElementById(divid);
    
    if (div.scrollTop>0 && doLoop)
    {
    div.scrollTop-=3;
    t = setTimeout("scrollDivToTop('" + divid + "')", 1);
    }
    else clearTimeout(t);
    }
    
    function scrollDivToBottom(divid)
    {
    
    var div = document.getElementById(divid);
    
    if (div.scrollTop<999999999 && doLoop)
    {
    div.scrollTop+=3;
    t = setTimeout("scrollDivToBottom('" + divid + "')", 1);
    }
    else clearTimeout(t);
    }
    
    function stop()
    {
    doLoop = false;
    setTimeout('doLoop = true;', 5);
    }
    
    </script>

  2. #2
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Stuff

    ^ This ^ May ^ Help ^

    -magicyte

  3. #3
    Join Date
    Oct 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by magicyte View Post
    Stuff

    ^ This ^ May ^ Help ^

    -magicyte
    I've read that thread already, but that one line of code doesn't seem so straightforward. ;P

    I think I need something like this:

    Code:
    <script type="text/javascript">
    var scrollExample = new Fx.Scroll($('content'));
    scrollExample.start(0, 120);
    </script>
    But then, to activate it, could I just do onClick?

    Code:
    <a onclick="scrollExample.start();">scroll</a>
    I've actually tried this already (and yes, I have the correct div ID), but I've probably got the onclick part wrong.

  4. #4
    Join Date
    Oct 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Nevermind, I found a more simple solution:

    http://scripterlative.com?softdivscroll

    No need for onClick scripts. ;P

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •