Scroll to bottom of div?

前端 未结 30 2701
日久生厌
日久生厌 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-21 12:14

    If this is being done for scrolling to the bottom of chat window, do the following

    The idea of scrolling to a particular div in the chat was the following

    1) Each chat div consisting of Person, time and message is run in a for loop with class chatContentbox

    2) querySelectorAll finds all such arrays. It could be 400 nodes (400 chats)

    3) go to the last one

    4) scrollIntoView()

    let lastChatBox = document.querySelectorAll('.chatContentBox'); 
    lastChatBox = lastChatBox[lastChatBox.length-1]; 
    lastChatBox.scrollIntoView(); 
    

提交回复
热议问题