Skip to content

Commit 9a2bf28

Browse files
committed
(clean) scrollToBottom function
1 parent 2a26e7e commit 9a2bf28

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/ChatWindow/Room/Room.vue

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -489,22 +489,15 @@ export default {
489489
const element = this.$refs.scrollContainer
490490
if (!element) return
491491
492-
function scrollToBottom() {
493-
setTimeout(() => {
494-
const options = { top: element.scrollHeight, behavior: 'smooth' }
495-
element.scrollTo(options)
496-
}, 50)
497-
}
498-
499492
if (oldVal && newVal && oldVal.length === newVal.length - 1) {
500493
this.newMessages = []
501494
this.loadingMessages = false
502495
503496
if (this.getBottomScroll(element) < 60) {
504-
return scrollToBottom()
497+
return this.scrollToBottom()
505498
} else {
506499
if (newVal[newVal.length - 1].senderId === this.currentUserId) {
507-
return scrollToBottom()
500+
return this.scrollToBottom()
508501
} else {
509502
this.scrollIcon = true
510503
return this.scrollMessagesCount++
@@ -850,8 +843,10 @@ export default {
850843
return scrollHeight - clientHeight - scrollTop
851844
},
852845
scrollToBottom() {
853-
const element = this.$refs.scrollContainer
854-
element.scrollTo({ top: element.scrollHeight, behavior: 'smooth' })
846+
setTimeout(() => {
847+
const element = this.$refs.scrollContainer
848+
element.scrollTo({ top: element.scrollHeight, behavior: 'smooth' })
849+
}, 50)
855850
},
856851
onChangeInput() {
857852
this.keepKeyboardOpen = true

0 commit comments

Comments
 (0)