获取到顶部的距离

 
<template>
    <div ref="obtain"></div>
<template/>

 

<script>
 export default {
    data() {
        return {}
    },
    mounted() {
      // 滚动条的获取
      window.addEventListener('scroll', this.handleScrollx, true)
   },
    methods: {
        handleScrollx() {
          console.log('滚动高度', window.pageYOffset)
          console.log('距离顶部高度', this.$refs.obtain.getBoundingClientRect().top)
        }
    }
}
</ script>
posted @ 2020-06-22 15:55  昵称cart  阅读(183)  评论(0编辑  收藏  举报