Skip to content

Commit de5497b

Browse files
committed
(fix) auto scroll with new message
1 parent bfaab68 commit de5497b

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/ChatWindow/Room/Room.vue

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -479,20 +479,25 @@ export default {
479479
const element = this.$refs.scrollContainer
480480
if (!element) return
481481
482+
function scrollToBottom() {
483+
setTimeout(() => {
484+
const options = { top: element.scrollHeight, behavior: 'smooth' }
485+
element.scrollTo(options)
486+
}, 50)
487+
}
488+
482489
if (oldVal && newVal && oldVal.length === newVal.length - 1) {
483490
this.loadingMessages = false
484491
485-
if (
486-
newVal[newVal.length - 1].senderId === this.currentUserId ||
487-
this.getBottomScroll(element) < 60
488-
) {
489-
return setTimeout(() => {
490-
const options = { top: element.scrollHeight, behavior: 'smooth' }
491-
element.scrollTo(options)
492-
}, 50)
492+
if (this.getBottomScroll(element) < 60) {
493+
return scrollToBottom()
493494
} else {
494-
this.scrollIcon = true
495-
return this.scrollMessagesCount++
495+
if (newVal[newVal.length - 1].senderId === this.currentUserId) {
496+
return scrollToBottom()
497+
} else {
498+
this.scrollIcon = true
499+
return this.scrollMessagesCount++
500+
}
496501
}
497502
}
498503

0 commit comments

Comments
 (0)