CSS 关键帧动画

1.定义关键帧:

使用 @keyframes 规则来定义动画的名称和关键帧。

@keyframes example {
  0% {background-color: red;}
  50% {background-color: yellow;}
  100% {background-color: green;}
}

使用from和to

@keyframes example {
  from {
    background-color: red;
  }
  to {
    background-color: green;
  }
}

不能直接混合使用百分比和 from/to 关键字

 可以省略 0%100% 关键帧,但前提是你已经定义了其他百分比的关键帧。

@keyframes example {
  50% {
    background-color: yellow;
  }
}

2.使用动画:

div {
  width: 100px;
  height: 100px;
  background-color: blue;
  animation-name: example; /* 引用关键帧的名称 */
  animation-duration: 4s; /* 动画持续时间 */
  animation-timing-function: ease-in-out; /* 动画速度曲线 */
  animation-delay: 1s; /* 动画延迟时间 */
  animation-iteration-count: infinite; /* 动画循环次数 */
  animation-direction: alternate; /* 动画的方向 */
}

3.简写动画属性:

div {
  animation: example 4s ease-in-out 1s infinite alternate;
}

关于 animation-timing-function属性的设置可以参考我的另一篇CSS中transition过度-优快云博客

4.关于 animation-direction属性:

 1,normal  默认值

2, reverse   反向播放

3,  alternate    先反播在正播 , 交替进行

 

结语:

常用到的点就这些,一些东西没有讲到请见谅!

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值