mounted() { // 监听滚动事件
window.addEventListener('scroll', this.handleScroll)
},
// 离开这个页面销毁滚动条事件
beforeDestroy() {
window.removeEventListener('scroll', this.handleScroll)
},
methods: {
handleScroll() {
// 设备或屏幕高度
let clientHeight = document.documentElement.clientHeight || document.body.clientHeight
// 滚动区域到头部的距离
let scrollObj = document.getElementsByClassName('content')[0].scrollTop
// 滚动条的总高度
let scrollHeight = scrollObj.scrollHeight
}
}
如果发现不能实现滚动的话加true
window.addEventListener('scroll', this.handleScroll, true)