旋转后调整div宽度和高度
如果我有这些规则:
width:50px; height:100px; -moz-transform: rotate(0deg)
然后一个事件将变换更改为:
-moz-transform: rotate(90deg)
从逻辑上讲,这不应该自动交换宽度和高度吗?我需要旋转来切换宽度和高度以进行准确的位置检测。
谢谢,
乔
If I have these rules:
width:50px; height:100px; -moz-transform: rotate(0deg)
and then an event changes the transform to:
-moz-transform: rotate(90deg)
logically, shouldn't that automatically exchange the width and the height? I need the rotate to switch width and height for accurate position detection.
Thanks,
Joe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎变换是在其他所有操作之后应用的,因此宽度和高度不会更新。我能想到的最好的解决方案是使用旋转矩阵自己计算旋转尺寸:
将其转换为 JavaScript 很简单。您需要旋转所有四个角 (0,0) (w,0) (0,h) (w,h),然后旋转的尺寸就是旋转边界矩形的宽度和高度。
It seems like the transform is applied after everything else, so the width and height aren't updated. The best solution I can think of is to calculate the rotated dimensions yourself, using the rotation matrix:
It's straightforward to translate this into JavaScript. You need to rotate all four corners (0,0) (w,0) (0,h) (w,h) and then the rotated dimensions are the width and height of the rotated bounding rectangle.
这是我实现的最优雅的 JavaScript 解决方案。
Here's the most elegant JavaScript solution, that I have achieved.