Cross-browser Method For Setting Scrolltop Of An Element?
For example I have I a div tag with the scroll bar on the right of the div tag. I want to show the div with the last line, so I have this: document.getElementById('divscroll').sc
Solution 1:
scrollTop
works in all major browsers.
To scroll to the bottom of the element:
var div = document.getElementById('divscroll');
div.scrollTop = div.scrollHeight - div.clientHeight;
clientHeight
also works across browsers, and scrollHeight
mostly works.
Solution 2:
Make sure that overflow property is set:
<div id="divscroll" style="height: 100px; width: 100px; overflow: scroll;">
//// something something
</div>
Solution 3:
Try setting the scroll position to a real figure, instead of just an arbitrary big number:
document.getElementById("divscroll").scrollTop = document.getElementById("divscroll").scrollHeight;
Post a Comment for "Cross-browser Method For Setting Scrolltop Of An Element?"