Scroll from bottom to top

0

I have a div that encompasses a chat, I load the last 15 messages, but the problem is that I want her scroll to start from the top, old.

NOTE: This div is overflowed: auto. And I want the scroll to start from the bottom as soon as the page loads.

All CSS code:

.panel-content .panel-group-msgs{
    width: 100%;
    height: 350px;
    overflow: auto;
    margin-top: 10px;
    padding: 20px;
    background-color: #EBF0F0 !important;
}
.panel-content .panel-group-msgs::-webkit-scrollbar-track {
    background-color: transparent;
}
.panel-content .panel-group-msgs::-webkit-scrollbar {
    width: 6px;
    background: transparent;
}
.panel-content .panel-group-msgs::-webkit-scrollbar-thumb {
    background: #dad7d7;
    border-radius: 6px;
}

HTML and only the div and several subdivs with the messages loop (this making the layout of the system still) Print: I want the scroll to look like this when the page loads.

    
asked by anonymous 17.07.2016 / 18:11

1 answer

2

You can do this by giving a scrollTop with the height of the div

var divMensagens = document.getElementById('mensagens');
var height = divMensagens.scrollHeight;
divMensagens.scrollTop(height);
    
17.07.2016 / 18:50