Scroll to bottom of div?

前端 未结 30 2763
日久生厌
日久生厌 2020-11-21 11:56

I am creating a chat using Ajax requests and I\'m trying to get messages div to scroll to the bottom without much luck.

I am wrapping everything in this div:



        
30条回答
  •  长发绾君心
    2020-11-21 12:17

    Set the distance from the top of the scrollable element to be the total height of the element.

    const element = this.shadowRoot.getElementById('my-scrollable-div')
    element.scrollTop = element.scrollHeight
    

提交回复
热议问题