1

I got a strange result of offsetHeight combining with scale transforming. My simple HTML as below

  <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>

On the screen the second <div> is bigger (twice) than the first <div>. Thus I expected second <div>'s offsetHeight should be greater than the first one.

My question is: Why elem01.offsetHeight always equals to elem02.offsetHeight in this case? The browser does not use transform to calculate element's offsetHeight?

Thanks

1 Answer 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.