Scroll to bottom of div?

前端 未结 30 2695
日久生厌
日久生厌 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:06

    On my Angular 6 application I just did this:

    postMessage() {
      // post functions here
      let history = document.getElementById('history')
      let interval    
      interval = setInterval(function() {
        history.scrollTop = history.scrollHeight
        clearInterval(interval)
      }, 1)
    }
    

    The clearInterval(interval) function will stop the timer to allow manual scroll top / bottom.

提交回复
热议问题