How to keep a scrollbar always bottom?

后端 未结 5 2067
北荒
北荒 2020-12-05 14:28

I have a scroll-bar in a div element and initially it\'s position is top. Whenever i add some text to the div element then the scroll-bar does not move. Is there any way, th

5条回答
  •  失恋的感觉
    2020-12-05 15:13

    Here you go. Follow this concept.

    $('#messages').scrollTop($('#messages')[0].scrollHeight);
    #chatbox-history {
      overflow: none;
      position: relative;
      width: 100%;
      height: 200px;
      border: 1px solid #ccc;
    }
    #messages {
      overflow: auto;
      position: absolute;
      bottom: 0;
      width: 100%;
      max-height: 200px;
    }
    #messages div {
      border: 1px solid #e2e4e3;
      margin: 5px;
      padding: 10px;
      background: #fafafa;
    }
    
    
    asdjf ;asd
    ajsd fa ;skd f;s
    asdjf ;akjs d;lf a;lksd fj
    ajsd fkaj s;dlf a;ljsdl;fkja;lsd f; asd
    Wassup?

提交回复
热议问题