css制作旋转幻影
使用CSS制作旋转幻影效果
通过CSS的transform和animation属性可以创建旋转幻影效果,结合透明度和多重阴影增强视觉层次感。
HTML结构
<div class="phantom-rotate"></div>
CSS关键代码
.phantom-rotate {
width: 100px;
height: 100px;
background: rgba(100, 200, 255, 0.7);
border-radius: 50%;
position: relative;
box-shadow:
0 0 20px 10px rgba(100, 200, 255, 0.4),
0 0 40px 20px rgba(100, 200, 255, 0.2);
animation: spin 3s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg) scale(1); }
50% { transform: rotate(180deg) scale(1.2); }
to { transform: rotate(360deg) scale(1); }
}
增强幻影效果的技巧
通过伪元素创建多重残影层能显著提升效果。添加::before和::after伪元素,设置不同的动画延迟。
.phantom-rotate::before,
.phantom-rotate::after {
content: '';
position: absolute;
width: 100%;
height: 100%;
border-radius: inherit;
background: inherit;
opacity: 0.6;
}
.phantom-rotate::before {
animation: spin 3s linear infinite 0.5s;
}
.phantom-rotate::after {
animation: spin 3s linear infinite 1s;
}
颜色渐变与模糊处理
结合CSS滤镜和渐变背景可产生更动态的视觉效果。使用filter: blur()和background: linear-gradient()实现光晕扩散。
.phantom-rotate {
background: linear-gradient(
45deg,
rgba(100, 200, 255, 0.8),
rgba(200, 100, 255, 0.5)
);
filter: blur(2px);
}
性能优化建议
对需要高频动画的元素启用GPU加速,避免使用box-shadow等耗性能的属性。改用伪元素模拟阴影。
.phantom-rotate {
transform: translateZ(0);
}
.phantom-rotate::before {
width: 120%;
height: 120%;
top: -10%;
left: -10%;
background: radial-gradient(
circle,
rgba(100, 200, 255, 0.4) 0%,
transparent 70%
);
animation: none;
}






