http://www.saaraan.com/2013/04/creating-shout-box-facebook-styleからこのシャウト ボックスを追加しました。ライブ デモはこちらhttp://www.saaraan.com/2013/ で見ることができます。 04/creating-shout-box-facebook-style
スライダー自体を除いて、すべて正常に動作しています。上にスクロールしようとするたびに、自動的に下にスクロールします。上の位置にとどまりません。問題はここにあると思います。
// load messages every 1000 milliseconds from server.
load_data = {'fetch':1};
window.setInterval(function(){
$.post('shout.php', load_data, function(data) {
$('.message_box').html(data);
var scrolltoh = $('.message_box')[0].scrollHeight;
$('.message_box').scrollTop(scrolltoh);
});
}, 1000);
//method to trigger when user hits enter key
$("#shout_message").keypress(function(evt) {
if(evt.which == 13) {
var iusername = $('#shout_username').val();
var imessage = $('#shout_message').val();
post_data = {'username':iusername, 'message':imessage};
//send data to "shout.php" using jQuery $.post()
$.post('shout.php', post_data, function(data) {
//append data into messagebox with jQuery fade effect!
$(data).hide().appendTo('.message_box').fadeIn();
//keep scrolled to bottom of chat!
var scrolltoh = $('.message_box')[0].scrollHeight;
$('.message_box').scrollTop(scrolltoh);
//reset value of message box
$('#shout_message').val('');
具体的にはこちら
var scrolltoh = $('.message_box')[0].scrollHeight;
$('.message_box').scrollTop(scrolltoh);
そしてここ
//keep scrolled to bottom of chat!
var scrolltoh = $('.message_box')[0].scrollHeight;
$('.message_box').scrollTop(scrolltoh);
0 から 1 およびその他の数値を変更し、スクロールが正しく機能するように修正しましたが、最新のシャウトが表示されず、削除前に表示される最後のシャウトであるシャウト 25 が表示されます。これが意味をなすかどうかはわかりませんが、どんな助けでも素晴らしいでしょう.
上からの最初のリンクはコード全体を示し、2 番目のリンクは例を示します