css3菊花动画制作
使用CSS3制作菊花动画
菊花动画是一种常见的加载动画,通过多个旋转的线条模拟花瓣效果。以下是实现方法:

基础菊花动画
通过关键帧动画和旋转效果实现:

.spinner {
width: 40px;
height: 40px;
position: relative;
margin: 100px auto;
}
.spinner div {
width: 6px;
height: 6px;
background-color: #333;
border-radius: 100%;
position: absolute;
animation: spinner 1.2s infinite ease-in-out;
}
.spinner div:nth-child(1) {
top: 0;
left: 20px;
animation-delay: -0.4s;
}
.spinner div:nth-child(2) {
top: 5px;
left: 5px;
animation-delay: -0.8s;
}
.spinner div:nth-child(3) {
top: 20px;
left: 0;
animation-delay: -1.2s;
}
/* 继续添加更多花瓣... */
@keyframes spinner {
0%, 100% {
transform: scale(0.4);
}
50% {
transform: scale(1);
}
}
线条式菊花动画
使用伪元素创建更细长的花瓣效果:
.flower-loader {
width: 50px;
height: 50px;
position: relative;
}
.flower-loader:before, .flower-loader:after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 3px solid transparent;
border-top-color: #3498db;
border-radius: 50%;
animation: spin 2s linear infinite;
}
.flower-loader:after {
border-top-color: #e74c3c;
animation-delay: 0.5s;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
高级菊花动画
结合缩放和旋转效果:
.advanced-spinner {
width: 60px;
height: 60px;
position: relative;
}
.advanced-spinner div {
position: absolute;
width: 100%;
height: 100%;
border: 4px solid transparent;
border-radius: 50%;
border-top-color: #2ecc71;
animation: advancedSpin 2s cubic-bezier(0.4, 0.1, 0.4, 1) infinite;
}
.advanced-spinner div:nth-child(2) {
border-top-color: #f1c40f;
animation-delay: -0.5s;
}
@keyframes advancedSpin {
0% {
transform: rotate(0deg) scale(0.8);
}
50% {
transform: rotate(180deg) scale(1.2);
}
100% {
transform: rotate(360deg) scale(0.8);
}
}
优化技巧
- 使用
transform-origin控制旋转中心点 - 调整
animation-timing-function改变运动曲线 - 通过
animation-delay创建交错动画效果 - 使用CSS变量方便修改颜色和尺寸
这些方法可以组合使用,创造出各种不同风格的菊花加载动画效果。





