mirror of
https://github.com/xfgryujk/blivechat.git
synced 2025-03-23 08:10:56 +08:00
优化前端防卡代码
This commit is contained in:
parent
b7e06652b4
commit
00e1f31f84
@ -97,6 +97,14 @@ export default {
|
|||||||
return this.atBottom/* || this.allowScroll*/
|
return this.atBottom/* || this.allowScroll*/
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
css(val) {
|
||||||
|
this.styleElement.innerText = val
|
||||||
|
},
|
||||||
|
canScrollToBottom(val) {
|
||||||
|
this.cantScrollStartTime = val ? null : new Date()
|
||||||
|
}
|
||||||
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.styleElement.innerText = this.css
|
this.styleElement.innerText = this.css
|
||||||
this.scrollToBottom()
|
this.scrollToBottom()
|
||||||
@ -109,11 +117,6 @@ export default {
|
|||||||
}
|
}
|
||||||
this.clearMessages()
|
this.clearMessages()
|
||||||
},
|
},
|
||||||
watch: {
|
|
||||||
css(val) {
|
|
||||||
this.styleElement.innerText = val
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
addMessage(message) {
|
addMessage(message) {
|
||||||
this.addMessages([message])
|
this.addMessages([message])
|
||||||
@ -446,29 +449,18 @@ export default {
|
|||||||
scrollToBottom() {
|
scrollToBottom() {
|
||||||
this.$refs.scroller.scrollTop = Math.pow(2, 24)
|
this.$refs.scroller.scrollTop = Math.pow(2, 24)
|
||||||
this.atBottom = true
|
this.atBottom = true
|
||||||
if (this.canScrollToBottom) {
|
|
||||||
this.cantScrollStartTime = null
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onScroll() {
|
onScroll() {
|
||||||
this.refreshCantScrollStartTime()
|
this.refreshCantScrollStartTime()
|
||||||
let scroller = this.$refs.scroller
|
let scroller = this.$refs.scroller
|
||||||
this.atBottom = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < SCROLLED_TO_BOTTOM_EPSILON
|
this.atBottom = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < SCROLLED_TO_BOTTOM_EPSILON
|
||||||
if (this.canScrollToBottom) {
|
|
||||||
this.cantScrollStartTime = null
|
|
||||||
}
|
|
||||||
this.flushMessagesBuffer()
|
this.flushMessagesBuffer()
|
||||||
},
|
},
|
||||||
canScrollToBottomOrTimedOut() {
|
canScrollToBottomOrTimedOut() {
|
||||||
if (this.canScrollToBottom) {
|
if (this.canScrollToBottom) {
|
||||||
this.cantScrollStartTime = null
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// 防止在OBS中卡住,超过一定时间也可以自动滚动
|
// 防止在OBS中卡住,超过一定时间也可以自动滚动
|
||||||
if (!this.cantScrollStartTime) {
|
|
||||||
this.cantScrollStartTime = new Date()
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return new Date() - this.cantScrollStartTime >= 10 * 1000
|
return new Date() - this.cantScrollStartTime >= 10 * 1000
|
||||||
},
|
},
|
||||||
refreshCantScrollStartTime() {
|
refreshCantScrollStartTime() {
|
||||||
|
Loading…
Reference in New Issue
Block a user