Make the scroll scroll to the bottom of the page automatically

0

I'm developing an application where the user asks a question and the server delivers a response, I'm having trouble getting the scroll bar to follow the conversation, so far I'm having the chat history on the screen, but I have you drag with the mouse to see the new messages. I'm using JSF with AJAX.

<div id="perguntaResposta">
                <ul class="messages">
                    <h:panelGroup id="dialogo">
                        <ui:repeat var="conversa" value="#{chat.conversas}">
                            <h:panelGroup rendered="#{conversa.usuario == 1}">
                                <li class="message right appeared">
                                    <div class="avatar"></div>
                                    <div class="text_wrapper">
                                        <h:outputText value="#{conversa.intereacaoFala}" />
                                    </div>
                                </li>
                            </h:panelGroup>
                            <h:panelGroup rendered="#{conversa.usuario == 2}">
                                <li class="message left appeared">
                                    <div class="avatar"></div>
                                    <div class="text_wrapper">
                                        <h:outputText value="#{conversa.intereacaoFala}"/>
                                    </div>
                                </li>
                            </h:panelGroup>
                        </ui:repeat>
                    </h:panelGroup>
                </ul>
            </div> 
    
asked by anonymous 15.10.2016 / 17:10

1 answer

2

You can force the user to go to the bottom of the page with Javascript:

var heightPage = document.body.scrollHeight;
window.scrollTo(0 , heightPage);

In case you need to ask any questions: link

    
20.10.2016 / 14:27