vue获取元素距离顶部距离,获取页面高度
核心代码<template><div ref="obtain"></div><template/><script>export default {data() {return {screenHeight: document.body.clientHeight // 获取页面高度}},mounted() { // 滚动条的获取
·
核心代码
<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>
更多推荐
已为社区贡献1条内容
所有评论(0)