- 获得dom元素的宽度(高度)
<style>
.han {
width: 100px;
height: 120px;
}
</style>
<body>
<div class="han"></div>
</body>
- 如果dom为内联样式
dom.style.wdith/height
- dom.getBoundingClientRect().width/height
let han = document.querySelector('.han')
console.log(han.getBoundingClientRect().width)//100 不带单位
- dom.offsetHeight/Width
console.log(han.offsetHeight)//120 不带单位
- window.getComputedStyle(dom).width
console.log(window.getComputedStyle(han).width)//100px 带单位