Using scrollTo() with a <div>

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bugboy
    New Member
    • Sep 2007
    • 160

    Using scrollTo() with a <div>

    I need to be able to automatically scroll a div all the way to the right when new content is added to it via ajax. I've tried direction: rtl; which works in FF and IE but not Safari.. so i'm trying this:

    Code:
    <script type="text/javascript">
    function scrollDiv()
      {
      document.getElementById('id').scrollTo(1000,0)
      }
    </script>
    
    <div onmouseover="scrollDiv()"></div>
    Any suggestions?

    The user's mouse will be over the div when new content is added via onclick so i'm using onmouseover to trigger it since onload doesn't work with divs.

    Thanks for your help!
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You could use element.scrollI ntoView() or you could set the scrollLeft to the scrollWidth.

    Comment

    • bugboy
      New Member
      • Sep 2007
      • 160

      #3
      Thanks that works great!

      Kind regards,

      Bugboy

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Pleased it does! :)

        Comment

        Working...