diff --git a/site/src/components/chat/script.js b/site/src/components/chat/script.js index 9577557..b1e914e 100644 --- a/site/src/components/chat/script.js +++ b/site/src/components/chat/script.js @@ -29,11 +29,29 @@ export default user(value) { this.userName = value.name + }, + + messages() + { + window.requestAnimationFrame(() => + { + if(this.atBottom) + { + this.$messages.scrollTop = this.$innerMessages.offsetHeight - this.$messages.offsetHeight + } + }) } }, + created() + { + this.atBottom = true + }, + mounted() { + this.$messages = this.$el.querySelector('.messages') + this.$innerMessages = this.$messages.querySelector('.inner-messages') }, methods: @@ -68,6 +86,11 @@ export default this.$store.commit('setPendingMessage', { text: this.messageText }) this.messageText = '' } + }, + + onMessagesScroll() + { + this.atBottom = this.$messages.scrollTop + this.$messages.offsetHeight >= this.$innerMessages.offsetHeight - 15 } } } \ No newline at end of file diff --git a/site/src/components/chat/template.html b/site/src/components/chat/template.html index 1a17b71..b96085d 100644 --- a/site/src/components/chat/template.html +++ b/site/src/components/chat/template.html @@ -3,16 +3,18 @@ Discussions
-
-
-
- {{ message.time }} -
-
- {{ message.user.name }} -
-
- {{ message.text }} +
+
+
+
+ {{ message.time }} +
+
+ {{ message.user.name }} +
+
+ {{ message.text }} +