旋转后如何获取元素的真实宽度和高度?

我想知道如何在旋转后获得元素的原始尺寸,当我使用transform: rotate()并尝试在旋转后获得尺寸时,使用element.getBoundingClientRect()它返回不同的宽度高度,是否有可能在旋转后获得真实尺寸元素?

let div1 = document.getElementById('one')
let div2 = document.getElementById('two')

// Here the width and height is 50 and 80
console.log(div1.getBoundingClientRect())

// Here because i used transform rotate the width is 86 and height 94
console.log(div2.getBoundingClientRect())
div#one {
  width: 50px;
  height: 80px;
  background-color: red;
}

div#two {
  width: 50px;
  height: 80px;
  background-color: red;
  transform: rotate(35deg);
}
<div></div>
<br/>
<div></div>
以上是旋转后如何获取元素的真实宽度和高度?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>