// 滚动到底部
handleScrollBottom(){
this.$nextTick(function () {
// 设置滚动最底部
let msgBody = document.getElementsByClassName('message-body')[0]
//设置滚动条到最底部
if(msgBody.scrollHeight > msgBody.clientHeight) {
setTimeout(function () {
//设置滚动条到最底部
msgBody.scrollTop = msgBody.scrollHeight;
}, 0);
}
})
},
// 滚动到顶部加载上一页
handlerScrollTop () {
let _this = this
let msgBody = document.getElementsByClassName('message-body')[0]
if (_this.topStatus === 'more' && msgBody.scrollTop <= 100) {
// console.log('执行触顶加载', msgBody.scrollHeight, msgBody.scrollTop)
_this.nextMessageList()
}
},
使用方法
// 滚动到底部
_this.handleScrollBottom()
// 监听滚动到顶部
_this.$nextTick(function () {
let msgBody = document.getElementsByClassName('message-body')[0]
msgBody.addEventListener('scroll', _this.handlerScrollTop)
})