Automatically scroll down chat div

后端 未结 11 2260
时光取名叫无心
时光取名叫无心 2020-12-05 07:43

I have this code, to load chat

function getMessages(letter) {
  var div = $(\'#messages\');
  $.get(\'msg_show.php\', function (data) {
    div.html(data);
          


        
11条回答
  •  我在风中等你
    2020-12-05 08:10

    What you need to do is divide it into two divs. One with overflow set to scroll, and an inner one to hold the text so you can get it's outersize.

    textdiv.html(""); $.each(chatMessages, function (i, e) { textdiv.append("" + e + "
    "); }); chatdiv.scrollTop(textdiv.outerHeight());

    You can check out a jsfiddle here: http://jsfiddle.net/xj5c3jcn/1/

    Obviously you don't want to rebuild the whole text div each time, so take that with a grain of salt - just an example.

提交回复
热议问题