变换后的宽度/高度

编程入门 行业动态 更新时间:2024-10-26 11:13:56
本文介绍了变换后的宽度/高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在应用 transform:rotate(45deg); ?

例如,旋转后的11x11方块变成17x17(Chrome结果),但是JavaScript仍会返回原始宽度/高度 - 10x10。

Like, 11x11 square after rotation becomes 17x17 (Chrome result), but javascript still returns original width/height - 10x10.

如何获得此17x17? / p>

How do I get this 17x17?

推荐答案

即使你旋转的东西,它的尺寸不会改变,所以你需要一个包装。 尝试用另一个div元素包装div,并计算包装器的尺寸:

Even if you rotate something the dimensions of it do not change, so you need a wrapper. Try wrapping your div with another div element and count the wrappers dimensions:

<style type="text/css"> #wrap { border:1px solid green; float:left; } #box { -moz-transform:rotate(120deg); border:1px solid red; width:11px; height:11px; } </style> <script type="text/javascript"> $(document).ready(function() { alert($('#box').width()); alert($('#wrap').width()); }); </script> </head> <body> <div id="wrap"> <div id="box"></div> </div> </body>

已修改:封装解决方案无法正常工作,不会自动调整到内部div的内容。遵循数学解:

Redited: the wrapper solution is not working properly, as the wrapper is not automatically adjusted to the contents of the inner div. Follow the mathematical solution:

var rotationAngle; var x = $('#box').width()*Math.cos(rotationAngle) + $('#box').height()*Math.sin(rotationAngle);

更多推荐

变换后的宽度/高度

本文发布于:2023-11-12 01:15:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580093.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:宽度   高度

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!