css3的animation制作围绕椭圆轨道旋转,近大远小的动画
warning:
这篇文章距离上次修改已过201天,其中的内容可能已经有所变动。
要使用CSS3的animation制作一个围绕椭圆轨道旋转,且远离观察者的元素在近大远小的动画,你可以使用scale
属性进行缩放控制,结合animation
和transform
属性。
以下是一个简单的例子:
HTML:
<div class="ellipse"></div>
CSS:
@keyframes rotate {
0% {
transform: rotateX(0deg) rotateY(0deg);
transform-origin: 50% 50%;
}
100% {
transform: rotateX(360deg) rotateY(360deg);
}
}
.ellipse {
width: 100px;
height: 50px;
background: blue;
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
margin-top: -25px;
margin-left: -50px;
animation: rotate 5s infinite linear;
transform-style: preserve-3d;
}
.ellipse:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: red;
border-radius: 50%;
transform: scale(0);
animation: scale-up 5s infinite alternate ease-in-out;
}
@keyframes scale-up {
0% {
transform: scale(0);
}
100% {
transform: scale(1);
}
}
在这个例子中,.ellipse
是动画的基本元素,围绕其中心旋转。:before
伪元素用来模拟远离观察者的效果,通过scale
动画在0到1之间变化来模拟大小的变化。rotate
动画控制.ellipse
的旋转。
你可以根据需要调整动画的时长和其他属性。
评论已关闭