核心代码
<template>
<div ref="obtain"></div>
<template/>
<script>
export default {
data() {
return {
screenHeight: document.body.clientHeight // 获取页面高度
}
},
mounted() {
// 滚动条的获取
window.addEventListener('scroll', this.handleScrollx, true)
},
methods: {
handleScrollx() {
console.log('滚动高度', window.pageYOffset)
console.log('距离顶部高度', this.$refs.obtain.getBoundingClientRect().top)
}
}
}
</ script>