css教程网 css教程网365css.cn
公告为您打开互联网世界的窗户关于本站
首页/属性速查/动画与变换

animation

关键帧动画,能循环、能多阶段,比 transition 更自由。

语法
animation: <name> <duration> <timing> <delay> <iteration> <direction> <fill-mode>
常用值
float 6s ease-in-out infinite alternate both
初始值
none 0s ease 0s 1 normal none running
继承
否

运行效果

示例改成别的值试试,差异一眼能看出来
查看代码
HTML
<div class="an"><i></i></div>
CSS
.an { padding: 20px 0 24px; }
.an i { display: block; width: 48px; height: 48px; border-radius: 12px; background: #2b57ff; animation: bob 2.4s ease-in-out infinite alternate; }
@keyframes bob {
  from { transform: translateY(0) rotate(0); }
  to { transform: translateY(-16px) rotate(12deg); }
}

使用要点

  • fill-mode: both 让元素在延迟期间保持第一帧,避免闪现。
  • 务必给 prefers-reduced-motion 加降级。