By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,668 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

Using scrollTo() with a <div>

bugboy
100+
P: 160
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!
Dec 3 '08 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
You could use element.scrollIntoView() or you could set the scrollLeft to the scrollWidth.
Dec 4 '08 #2

bugboy
100+
P: 160
Thanks that works great!

Kind regards,

Bugboy
Dec 4 '08 #3

acoder
Expert Mod 15k+
P: 16,027
Pleased it does! :)
Dec 4 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.