table触底监听,添加/删除样式
// table触底监听
export const bottomOutWatch = tabledom => {
tabledom.addEventListener('scroll', () => {
// 滚动距离 ,scrollLeft为横向距离,scrollTop 为纵向距离
let scrollTop = tabledom.scrollTop
// table的可视区域高度,clientWidth为可视宽度
let windowHeight = tabledom.clientHeight
// 滚动条高度,scrollWidth为滚动条纵向距离
let scrollHeight = tabledom.scrollHeight
if (scrollTop + windowHeight == scrollHeight) {
// 滚动到了底部,添加样式、执行操作
tabledom.parentElement.classList.remove('filtertable')
} else {
// console.log('没有到底部')
tabledom.parentElement.classList.add('filtertable')
}
})
}
事件调用
bottomOutWatch(this.$refs.table.bodyWrapper)