width/height after transform

前端 未结 5 1408
予麋鹿
予麋鹿 2020-11-27 16:00

How do I retrieve the width and height properties after I\'ve applied transform: rotate(45deg);?

Like, 11x11 square after rotation becomes 17x17 (Chrome

5条回答
  •  迷失自我
    2020-11-27 16:10

    Instead of calculating it yourself, you can get this via the HTMLDOMElement's getBoundingClientRect().

    This will return an object with the correct height and width, taking into account the transformation matrix.

    jsFiddle.

提交回复
热议问题