Scroll to bottom

This commit is contained in:
Pavel Djundik 2018-07-09 20:16:19 +03:00 committed by Pavel Djundik
parent eff6dcb514
commit f0390dae63
1 changed files with 21 additions and 2 deletions

View File

@ -4,7 +4,6 @@
class="window">
<div
id="chat"
ref="chat"
:data-id="channel.id"
:class="{
'hide-motd': !settings.motd,
@ -45,7 +44,10 @@
</span>
</div>
<div class="chat-content">
<div class="chat">
<div
ref="chat"
class="chat"
>
<div class="show-more">
<button
ref="loadMoreButton"
@ -97,6 +99,10 @@ export default {
root: this.$refs.chat,
});
}
this.$nextTick(() => {
this.$refs.chat.scrollTop = this.$refs.chat.scrollHeight;
});
},
mounted() {
if (this.historyObserver) {
@ -108,6 +114,19 @@ export default {
this.historyObserver.disconnect();
}
},
watch: {
"channel.messages": function() {
const el = this.$refs.chat;
if (el.scrollHeight - el.scrollTop - el.offsetHeight > 30) {
return;
}
this.$nextTick(() => {
el.scrollTop = el.scrollHeight;
});
}
},
methods: {
onShowMoreClick() {
let lastMessage = this.channel.messages[0];