您如何计算两个旋转的两个元素之间的x和y偏移,但具有不同的变换原点位置?
我想知道,我们如何计算两个相同旋转的两个相等元素之间的x和y偏移,但具有不同的变换原点位置。
我创建了一个示例片段,以更好地说明问题。
有两个150x100 PX矩形,一个是在0%0%的变换起源位置旋转,而另一个则为50%50%。在特定旋转时计算这两个矩形之间的偏移的公式是什么?
.wrapper {
position: relative;
background: silver;
margin: 150px;
width: 150px;
height: 100px;
}
.div-1, .div-2 {
position: absolute;
top: 0;
left: 0;
width: 150px;
height: 100px;
border: 1px solid black;
animation: rotate 30s linear infinite;
}
.div-1 {
transform-origin: top left;
}
.div-2 {
transform-origin: center center;
}
@keyframes rotate {
100% {
transform: rotate(360deg);
}
}
<div class="wrapper">
<div class="div-1"></div>
<div class="div-2"></div>
</div>
I would like to know, how can we calculate the X and Y offset between two equal elements with the same rotation, but with a different transform origin positions.
I've created an example snippet to help better illustrate the problem.
There are two 150x100 px rectangles, one is being rotated at the transform origin position of 0% 0%, while other at 50% 50%. What would be the formula for calculating the offset between these two rectangles at specific rotation?
.wrapper {
position: relative;
background: silver;
margin: 150px;
width: 150px;
height: 100px;
}
.div-1, .div-2 {
position: absolute;
top: 0;
left: 0;
width: 150px;
height: 100px;
border: 1px solid black;
animation: rotate 30s linear infinite;
}
.div-1 {
transform-origin: top left;
}
.div-2 {
transform-origin: center center;
}
@keyframes rotate {
100% {
transform: rotate(360deg);
}
}
<div class="wrapper">
<div class="div-1"></div>
<div class="div-2"></div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论