I am trying to scroll to the end of the #chat-feed div with the overflow set to auto and stay there if the user does not scroll this div content. If they scroll back, the div should block at the bottom, and the new content will be displayed at the bottom.
Known Issues: I tried to implement this answer with my code, but I don't know Javascript well enough to make it work. If the content with chat-feed.php above the container, then the scroll remains at the top. It also seems that this answer does not take into account content downloaded from an external file.
Key things: new content should be displayed at the bottom, and the div should be scrolled to the lowest level when new content is loaded, IF users are already scrolling a little. If the user scrolls back, then he should be blocked to the bottom, and new content should be displayed below and be visible.
<div id="chat-feed" style="height: 200px; width: 300px; overflow: auto;"></div> <script> $(document).ready(function(){ setInterval(function(){ $('#chat-feed').load("chat-feed.php").fadeIn("slow"); }, 1000); }); </script>
Demo link
source share