目前,Element.getBoundingClientRect()
给出了元素的位置和尺寸,但它会通过 CSStransform
属性自动考虑转换。如何在没有转换的情况下获得矩形?
在下面的示例中,我希望输出为10 10 100 100
.
const rect = div.getBoundingClientRect()
document.write(`${rect.left} ${rect.top} ${rect.width} ${rect.height}`)
body {
margin: 10px;
}
div {
background: red;
width: 100px;
height: 100px;
transform: translate(1px, 1px) scale(0.5)
}
<div id="div"></div>