I need help creating a finite scroll bottom to top. Something like facebook messages.
I have checked this question but doesn't seem to work for me the way it supposed to. The problem is when I reach the top of the div and the end of the message list, it scrolls down and I can't see the the first few messages. How do I stop this from happening
And also, when new messages are prepended, the existing messages are pushed down, causing the user to lose their "viewing" place.
Here is what I have:
$(document).ready(function(){
$('#message_board').scrollTop($('#message_board')[0].scrollHeight);
});
$('#message_board').on('scroll', function() {
var scroll = $('#message_board').scrollTop();
if (scroll == 0) {
// Store eference to first message
var firstMsg = $('.bubble-left:first, .bubble-right:first');
// Prepend new message here
var content;
$.get("ajax/scripts/msg_lst.php?p=<?php echo htmlentities(isset($_GET['p']) ? $_GET['p'] : ''); ?>&f=" + ($('.bubble-left, .bubble-right').length), function(data){
content= data;
$('#message_board').prepend(content);
});
// After adding new message(s), set scroll to position of
// what was the first message
$('#message_board').scrollTop(firstMsg.offset().top);
}
});