1

我得到了 offsetHeight 与比例变换相结合的奇怪结果。我的简单 HTML 如下

  <body>
    <div id="id01">
      Some Text
    </div>
    <div id="id02" style="transform-origin: left top; transform: scale(2)">
      Some Text
    </div>
  </body>

  <script>
    var elem01 = document.getElementById('id01');
    var elem02 = document.getElementById('id02');
    alert(elem01.offsetHeight == elem02.offsetHeight);   // Always show true???
  </script>

在屏幕上,第二个<div>比第一个大(两倍)<div>。因此,我预计 second<div>的 offsetHeight 应该大于第一个。

我的问题是:为什么在这种情况下elem01.offsetHeight总是等于?elem02.offsetHeight浏览器不transform用于计算元素的offsetHeight?

谢谢

4

1 回答 1

1

The transform affects the pixel ratio not the actual amount of pixels in the DOM.

This previous question has some insights and possible solutions.

于 2013-09-19T16:39:09.493 回答