【发布时间】:2020-04-18 21:41:36
【问题描述】:
如何调整小球的旋转半径,使其接触橙色容器边框
.bg {
background-color: blue;
display: flex;
align-items: center;
justify-content: center;
}
.ball-container {
position: relative;
display:flex;
justify-content:center;
align-items:center;
background-color: orange;
width: 250px;
height: 250px;
}
.ball {
position: absolute;
width: 24px;
height: 24px;
background-color: white;
border-radius: 50%;
top: 125px - 12px;
left: 125px - 12px;
animation-name: ball_moves;
animation-duration: 1.5s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-direction: initial;
}
.ball:nth-child(1) {
transform-origin: top left;
}
.ball:nth-child(2) {
transform-origin: top right;
}
.ball:nth-child(3) {
transform-origin: bottom left;
}
.ball:nth-child(4) {
transform-origin: bottom right;
}
@keyframes ball_moves {
0% {
transform: rotateZ(0);
}
100% {
transform: rotateZ(360deg);
}
}
<div class="bg">
<div class="ball-container">
<div class="ball"></div>
<div class="ball"></div>
<div class="ball"></div>
<div class="ball"></div>
</div>
</div>
【问题讨论】:
-
调整变换原点值。
-
我试过这个,但无法将所有四个球移动到不同的方向,因为它们现在正在向所有四个方向移动。你能帮我多一点吗?
标签: html css css-animations css-transforms