I am trying to scroll to the bottom of a div #chat-feed
with overflow set to auto and stay there unless a user scrolls that div's content up. If they scroll back down, the div should lock to the bottom and new content will be displayed at the bottom.
Known issues: I have tried implementing this answer with my code but I do not know Javascript well enough yet to get it working. If content from chat-feed.php
is taller than the container then the scroll stays at the top. It also seems like the answer given does not respect content loaded from an external file.
Key things: new content should show at the bottom and the div should scroll to the bottom when new content loads UNLESS the users has already scrolled up a bit. If the user scrolls back down, then it should lock to the bottom and new content be displayed at the bottom 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>
hey
` lines. Can you verify with externally loaded content and then add a line to the file and see if it scrolls as desired? – Damien Mar 06 '17 at 01:08