Connecting Tech Pros Worldwide Forums | Help | Site Map

Using scrollTo() with a <div>

bugboy's Avatar
Familiar Sight
 
Join Date: Sep 2007
Location: Ontario
Posts: 146
#1: Dec 3 '08
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:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function scrollDiv()
  3.   {
  4.   document.getElementById('id').scrollTo(1000,0)
  5.   }
  6. </script>
  7.  
  8. <div onmouseover="scrollDiv()"></div>
  9.  
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's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Dec 4 '08

re: Using scrollTo() with a <div>


You could use element.scrollIntoView() or you could set the scrollLeft to the scrollWidth.
bugboy's Avatar
Familiar Sight
 
Join Date: Sep 2007
Location: Ontario
Posts: 146
#3: Dec 4 '08

re: Using scrollTo() with a <div>


Thanks that works great!

Kind regards,

Bugboy
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Dec 4 '08

re: Using scrollTo() with a <div>


Pleased it does! :)
Reply

Tags
auto, div, javascript, scroll, scrollto


Similar JavaScript / Ajax / DHTML bytes