I have a div with overflow set to scroll which essentially streams data line by line off a file. I\'d like to scroll automatically to the bottom of the div whenever the stream o
There's no way to automatically scroll an element to the bottom. Use element.scrollTop = element.scrollHeight
.
If you don't know when the element is going to resize, you could add a poller:
(function(){
var element = document.getElementById("myElement");
var lastHeight = element.scrollHeight;
function detectChange(){
var currentHeight = element.scrollHeight;
if(lastHeight != currentHeight){
element.scrollTop = currentHeight;
lastHeight = currentHeight;
}
}
detectChange();
setInterval(detectChange, 200); //Checks each 200ms = 5 times a second
})();