通过id class ref 获取元素的高度和宽度

dom 结构

<div  id="id1" class="class1" ref="ref1"  style="width: 100px; height: 100px;">div>

通过 id 获取高度宽度

let  widthid1 = document.getElementById("id1").offsetWidth
let  heightid = document.getElementById("id1").offsetHeight

通过class 获取高度宽度

let  widthclass1 = document.getElementsByClassName("class1").offsetWidth
let  heightclass1 = document.getElementsByClassName("class1").offsetHeight

通过ref 获取高度宽度

let widthref1 = this.$refs.ref1.offsetWidth
let heightref1 = this.$refs.ref1.offsetHeight

你可能感兴趣的:(vue,web,css,html5,html,vue.js,jquery,typescript)