1. <legend id='WcVXN'><style id='WcVXN'><dir id='WcVXN'><q id='WcVXN'></q></dir></style></legend>

    <small id='WcVXN'></small><noframes id='WcVXN'>

    • <bdo id='WcVXN'></bdo><ul id='WcVXN'></ul>

  2. <i id='WcVXN'><tr id='WcVXN'><dt id='WcVXN'><q id='WcVXN'><span id='WcVXN'><b id='WcVXN'><form id='WcVXN'><ins id='WcVXN'></ins><ul id='WcVXN'></ul><sub id='WcVXN'></sub></form><legend id='WcVXN'></legend><bdo id='WcVXN'><pre id='WcVXN'><center id='WcVXN'></center></pre></bdo></b><th id='WcVXN'></th></span></q></dt></tr></i><div id='WcVXN'><tfoot id='WcVXN'></tfoot><dl id='WcVXN'><fieldset id='WcVXN'></fieldset></dl></div>
      <tfoot id='WcVXN'></tfoot>

      旋转后调整div的宽度和高度

      时间:2023-10-13
          <legend id='HrRPC'><style id='HrRPC'><dir id='HrRPC'><q id='HrRPC'></q></dir></style></legend>

          <small id='HrRPC'></small><noframes id='HrRPC'>

              <tbody id='HrRPC'></tbody>

          • <tfoot id='HrRPC'></tfoot>
              <bdo id='HrRPC'></bdo><ul id='HrRPC'></ul>
              <i id='HrRPC'><tr id='HrRPC'><dt id='HrRPC'><q id='HrRPC'><span id='HrRPC'><b id='HrRPC'><form id='HrRPC'><ins id='HrRPC'></ins><ul id='HrRPC'></ul><sub id='HrRPC'></sub></form><legend id='HrRPC'></legend><bdo id='HrRPC'><pre id='HrRPC'><center id='HrRPC'></center></pre></bdo></b><th id='HrRPC'></th></span></q></dt></tr></i><div id='HrRPC'><tfoot id='HrRPC'></tfoot><dl id='HrRPC'><fieldset id='HrRPC'></fieldset></dl></div>
                本文介绍了旋转后调整div的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                如果我有这些规则:

                <上一页>宽度:50px;高度:100px;-moz 变换:旋转(0 度)

                然后一个事件将转换更改为:

                <上一页>-moz 变换:旋转(90 度)

                从逻辑上讲,这不应该自动交换宽度和高度吗?我需要旋转来切换宽度和高度以进行准确的位置检测.

                谢谢,

                解决方案

                似乎转换是在其他所有内容之后应用的,所以宽度和高度没有更新.我能想到的最佳解决方案是使用旋转矩阵自己计算旋转尺寸:

                [ cos X -sin X ] [ width ][ 罪 X cos X ] [ 高度 ]

                将其转换为 JavaScript 很简单.您需要旋转所有四个角 (0,0) (w,0) (0,h) (w,h),然后旋转的尺寸是旋转边界矩形的宽度和高度.

                var angle = angle_in_degrees * Math.PI/180,sin = Math.sin(角度),cos = Math.cos(角度);//(0,0) 保持为 (0, 0)//(w,0) 旋转var x1 = cos * 宽度,y1 = sin * 宽度;//(0,h) 旋转var x2 = -sin * 高度,y2 = cos * 高度;//(w,h) 旋转var x3 = cos * 宽度 - sin * 高度,y3 = sin * 宽度 + cos * 高度;var minX = Math.min(0, x1, x2, x3),maxX = Math.max(0, x1, x2, x3),minY = Math.min(0, y1, y2, y3),maxY = Math.max(0, y1, y2, y3);var rotateWidth = maxX - minX,旋转高度 = maxY - minY;

                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

                解决方案

                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:

                [ cos X     -sin X ] [ width  ]
                [ sin X      cos X ] [ height ]
                

                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.

                var angle = angle_in_degrees * Math.PI / 180,
                    sin   = Math.sin(angle),
                    cos   = Math.cos(angle);
                
                // (0,0) stays as (0, 0)
                
                // (w,0) rotation
                var x1 = cos * width,
                    y1 = sin * width;
                
                // (0,h) rotation
                var x2 = -sin * height,
                    y2 = cos * height;
                
                // (w,h) rotation
                var x3 = cos * width - sin * height,
                    y3 = sin * width + cos * height;
                
                var minX = Math.min(0, x1, x2, x3),
                    maxX = Math.max(0, x1, x2, x3),
                    minY = Math.min(0, y1, y2, y3),
                    maxY = Math.max(0, y1, y2, y3);
                
                var rotatedWidth  = maxX - minX,
                    rotatedHeight = maxY - minY;
                

                这篇关于旋转后调整div的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何围绕轴旋转 Three.js Vector3? 下一篇:变换模糊文本:在 Chrome 中旋转

                相关文章

                最新文章

              • <i id='6AqVV'><tr id='6AqVV'><dt id='6AqVV'><q id='6AqVV'><span id='6AqVV'><b id='6AqVV'><form id='6AqVV'><ins id='6AqVV'></ins><ul id='6AqVV'></ul><sub id='6AqVV'></sub></form><legend id='6AqVV'></legend><bdo id='6AqVV'><pre id='6AqVV'><center id='6AqVV'></center></pre></bdo></b><th id='6AqVV'></th></span></q></dt></tr></i><div id='6AqVV'><tfoot id='6AqVV'></tfoot><dl id='6AqVV'><fieldset id='6AqVV'></fieldset></dl></div>

                • <bdo id='6AqVV'></bdo><ul id='6AqVV'></ul>

                  <tfoot id='6AqVV'></tfoot>

                  1. <small id='6AqVV'></small><noframes id='6AqVV'>

                    <legend id='6AqVV'><style id='6AqVV'><dir id='6AqVV'><q id='6AqVV'></q></dir></style></legend>