I want to keep the screen focused on the bottom of a scrollable div whenever it gets loaded. What I have in my game is something like this:
<div id="storywindow" style="position:absolute;bottom:0;overflow:auto">\ \ <<display "PreDisplay">>\ \ <<display "Reactions">>\ <div id="location"><<print $location[$char.loc].desc>></div>\ \ <<display $story>>\ \ <div id="reports"><<display "Reports">></div>\ \ </div>\
var out = document.getElementById("out"); // allow 1px inaccuracy by adding 1 var isScrolledToBottom = out.scrollHeight - out.clientHeight <= out.scrollTop + 1; if(isScrolledToBottom) out.scrollTop = out.scrollHeight - out.clientHeight;
The source is this (3rd answer):
Thanks a lot in advance.