我正在使用 HTML div 元素javascript中基于角的调整大小.
下图显示了旋转调整大小操作:
基于角的调整大小当选择框 div 未旋转时工作完美(即rotate(0 deg)
).
旋转后,我正在使用右下角作为手柄调整选择框div的大小,当左上角需要保持在同一位置。
就像拥有四个手柄,调整大小时对角需要保持在同一位置。
但问题是,选择框左上角角未保持在同一位置.
我需要计算平移 x 和 y旋转后基于角调整大小的值。
已知值:
scale
, center_x
, center_y
, previous_x
, previous_y
, width
, height
, previous_width
, previous_height
, diff_width
, diff_height
, radian_angle
, rotated_degree
.
HTML 代码(selection box div
):
<div class="box" style="transform: translate(132px, 190px) rotate(0deg); width: 295px; height: 234px;">
<div>
用于旋转后调整大小的示例代码:
switch (handle) {
case 'bottom-right':
x = previous_x - ? ; //logic behind after rotated some angles..?
y = previous_y + ? ;
break;
case 'bottom-left':
x = ? ;
y = ? ;
break;
case 'top-left':
x = ? ;
y = ? ;
break;
case 'top-right':
x = ? ;
y = ? ;
break;
default:
}
当使用未旋转的 div 调整大小时,基于下角的调整大小代码非常有效(rotate(0 deg)
):
case 'bottom-right':
x = previous_x;
y = previous_y;
break;
case 'bottom-left':
x = previous_x - diff_width;
y = previous_y;
break;
如何计算旋转后平移 x 和 y 值以在调整大小时获得固定角。?