【发布时间】:2021-10-20 14:32:20
【问题描述】:
我有一个可以拖动 DIV 并调整其大小的系统。 您可以从顶部抓取,它会从底部生长。从底部抓起,它从顶部向下生长。与左、右和角相同。
这一切都是用 CSS 宽度/高度和 translate(x,y) 完成的,效果很好。
现在我正在添加旋转并使用如下内容:
style="transform: translate(100px,100px) rotate(-30deg);width:100px;height:50px;"
再一次,这一切都很好。
但是当我改变宽度或高度时,元素会向上/向下或向左/向右移动。
请参阅以下内容。绿色的 div 是原始的,红色的 div 扩展了宽度。你可以看到它是如何变化的。
<html>
<head>
<style>
body {
position: relative;
}
.thing {
position:absolute;
border: solid 1px #0f0;
transform: translate(100px, 100px) rotate(-30deg);
}
.thing2 {
position:absolute;
border: solid 1px #f00;
transform: translate(100px, 100px) rotate(-30deg);
}
</style>
</head>
<body>
<div class="thing" style="width:100px;height:50px;"></div>
<div class="thing2" style="width:150px;height:50px;"></div>
</body>
</html>
我知道我需要根据三角函数重新计算顶部/左侧,但还没有找到正确的计算方法。
另外,我想保持围绕中心的旋转枢轴,所以我不能只将枢轴点更改为角落之一。
【问题讨论】:
标签: html trigonometry css-transforms