vue獲取元素寬、高、距離左邊距離,右,上距離等還有XY坐標軸


   1.示例組件結構

<template>
  <div ref="myBox">
    <v-page :ref="myPage">
    </v-page>
  </div>
</template>

 2.獲取距離頂部的距離   

// ref=myBox元素
this.$refs.myBox.getBoundingClientRect().top
// ref=myPage組件
this.$refs.myPage.$el.getBoundingClientRect().top

  3.獲取高度

// ref=myBox元素
this.$refs.myBox.offsetHeight
// ref=myPage組件
this.$refs.myPage.$el.offsetHeight

  4. 獲取寬度

// ref=myBox元素
this.$refs.myBox.offsetWidth
// ref=myPage組件
this.$refs.myPage.$el.offsetWidth

 

未完待續..............

 


免責聲明!

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



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