title: auto scroll chat window
body: <p>I have made a simple chat UI using bootstrap 4 cards, I need a way to fix the message input to the bottom and to scroll the conversation automatically when the height of the window is filled by the sent and incoming messages. I've tried to fix the message input using a fixed position with the bottom set to 0 but the input then will take all the window width and this isn't what I want. Also for the text messages, I've tried to scroll the window using jQuery but it will not work and I need to scroll the window manually. another issue is with the code I'm using to add the sent and received messages to the DOM, I don't want to duplicate the code, but I can't imagine another solution to differentiate the incoming messages from the outgoing. </p>
  
  <p>Here is the code I've:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function scrollConversation() {
    $(".list-group").stop()
      .animate({
        scrollTop: $(".list-group")[0].scrollHeight
      }, 1000);
  }
  
  function outMessage(message) {
    //var html = '&lt;li class="list-group-item"&gt;';
    var html = '&lt;p class="speech-bubble-out float-right"&gt;' + message + '&lt;/p&gt;';
    //html += '&lt;/li&gt;';
    $('.list-group').append(html);
    //return ;
  }
  
  function inMessage(message) {
    //var html = '&lt;li class="list-group-item"&gt;';
    var html = '&lt;p class="speech-bubble-in float-left"&gt;' + message + '&lt;/p&gt;';
    //html += '&lt;/li&gt;';
    $('.list-group').append(html);
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>body {
    background-color: #f5f5f5;
  }
  
  body .speech-bubble-out {
    padding: 1em;
    position: relative;
    background: #dad8da;
    border-radius: .4em;
  }
  
  body .speech-bubble-out:after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    width: 0;
    height: 0;
    border: 0.563em solid transparent;
    border-left-color: #dad8da;
    border-right: 0;
    border-bottom: 0;
    margin-top: -0.281em;
    margin-right: -0.562em;
  }
  
  body .speech-bubble-in {
    padding: 1em;
    position: relative;
    background: #efe8b8;
    border-radius: .4em;
  }
  
  body .speech-bubble-in:after {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 0;
    height: 0;
    border: 0.563em solid transparent;
    border-right-color: #efe8b8;
    border-left: 0;
    border-bottom: 0;
    margin-top: -0.281em;
    margin-left: -0.562em;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="container"&gt;
    &lt;div class="row justify-content-center"&gt;
      &lt;div class="col-sm-12 col-md-7 col-lg-7 card"&gt;
        &lt;div class="card-body"&gt;
          &lt;!-- message list --&gt;
          &lt;ul class="list-group"&gt;&lt;/ul&gt;
          &lt;!-- text input --&gt;
          &lt;div class="input-group"&gt;
            &lt;input type="text" class="form-control" name="message" id=""&gt;
            &lt;div class="input-group-append"&gt;
              &lt;button class="btn btn-outline-secondary" id="sendMessage"&gt;Send&lt;/buttom&gt;
                    &lt;button class="btn btn-outline-secondary" id="sendAudio"&gt;Send Audio&lt;/button&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Any help will be appreciated.</p>