Vue 獲取當前距離屏幕頂部的距離


<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>

獲取當前頁面高度

export default {
    data() {
        return {
            // 頁面高度
            screenHeight: document.body.clientHeight,
            // 計算出的高度
            PageHeight: ''
        }
    },
    created() {
       this.GetHeight()
    },
    methods: {
        GetHeight() {
            // 根據頁面高度計算  (可以自定義邏輯)
            this.PageHeight = (this.screenHeight)
        }
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM