CSS animation that looks closer and farther from left to right, simulating the movement of a glass facade on a turntable
P粉208469050
2023-09-04 21:59:55
<p>I'm trying to create a CSS animation that moves horizontally from left to right while appearing closer and further away, simulating the movement of the glass on a turntable plate when viewed from the front. </p>
<p>I'm getting close, but it still doesn't look right, currently it looks like it's moving along a diamond shape instead of a circle. </p>
<p>This is what I tried..</p>
<p>
<pre class="brush:css;toolbar:false;">.roll {
display: block;
width: 100px;
height: 100px;
background: red;
margin: 10px auto 10px auto;
animation: roll 2s cubic-bezier(0.42, 0, 0.58, 1) infinite;
}
@keyframes roll {
0%,
100% {
transform: translateX(0%) scale(1);
}
20% {
transform: translateX(50%) scale(0.8);
}
50% {
transform: translateX(0%) scale(0.6);
}
80% {
transform: translateX(-50%) scale(0.8);
}
}</pre>
<pre class="brush:html;toolbar:false;"><div class="roll"></div></pre>
</p>
If you want to animate a square on a horizontal circle and have it face the viewer , you can use a 3D transform on the wrapper element and invert it on the square so that it stays For viewers.
The point is to rotate the element on the Y axis like "in real life".
Here is an example:
Please note that you need to use
transform-style:preserve-3d;
(More information about MDN)