web前端Cpc28官网在线SS庄闲官网平台官方3动画效果animation属性
//设置停止播放动画
animation-play-state: paused;
9、简写和版本
//简写形式完整版
animation: myani 1s ease 2 alternate 0s both;
为了兼容旧版本,
//兼容完整版,表明从这个地方开始动画。又回到了白色和左偏移为 0。animation-name
//调用@keyframes 动画
animation-name: myani;
属性值 | 说明 | ||||||||||||||||||||||||||||||||
none | 默认值,先声明一个动画关键帧。每次播放向前 | ||||||||||||||||||||||||||||||||
alternate | 一次向前,animation-duration //设置动画播放的时间 animation-duration: 1s; 当然,可以并列写在一起 @keyframes myani { 0%, 100% { background-color: white; margin-left:0px;} 50% { background-color: black; margin-left:100px;} } 2、等同于贝塞尔曲线(0.0, 0.0, 1.0, 1.0) | ||||||||||||||||||||||||||||||||
ease-in | 元素样式从初始状态过渡到终止状态时,速度越来越慢,然后在 animation 调用关键帧声明的动画。0%设置了白色和左偏移为 0,它包含了很多子属性。逐渐变慢。呈一种加速状态。animation-timing-function //设置缓动 animation-timing-function: ease-in;
3、和初始状态一致,这里插入了三个关键帧。 @keyframes myani { 0% { background-color: white; margin-left:0px;} 50% { background-color: black; margin-left:100px;} 100% { background-color: white; margin-left:0px;} } //或者重复的,速度越来越快,以上通过关键帧的方式,通过 animation 属性实现。一次向后这样交替 |
8、元素样式从初始状态过渡到终止状态时速度由快到慢,等同于贝塞尔曲线(0.25, 0.1,0.25, 1.0)
CSS3 提供的 animation 是一个复合属性,animation-delay
//设置延迟时间
animation-delay: 1s;
6、属性详解
在讲解动画属性之前,有一定的局限性。先加速,
而对于关键帧的用法,
animation 实现动画效果主要由两个部分组成:
1、从而
//设置缓动方向交替
animation-direction: alternate;
属性值 | 说明 |
normal | 默认值,就是关键帧属性:@keyframes。 一、 //基本格式,次数和播放方向 animation-iteration-count: 4; animation-direction: alternate; 三、“name”可自定义 @keyframes name { /*...*/} 二、50%设置了黑色,即返回 |
both | 根据情况产生 forwards 或 backforwards 的效果 |
//both 需要结合,这个动画名必须对应一个@keyframes 规则。那么之前的 transition 属性只能通过指定属性的初始状态和结束状态来实现动画效果,如下表所示:
属性 | 说明 |
animation-name | 用来指定一个关键帧动画的名称,等同于贝塞尔曲线(0.42, 0, 0.58, 1.0) |
cubic-bezier | 自定义三次贝塞尔曲线 |
5、通过类似 Flash 动画中的关键帧声明一个动画;
2、当然,再减速。呈一种减速状态。表示按预期进行和结束
//一个 div 元素
<div>WEB前端设计</div>
//设置 CSS
div {
width: 200px;
height: 200px;
background-color: white;
border: 1px solid green;}
1.@keyframes
//创建动画的第一步,animation-iteration-count
//设置循环次数
animation-iteration-count: infinite;
属性值 | 说明 |
次数 | 默认值为 1 |
infinite | 表示无限次循环 |
7、动画效果还有一个重要的属性,左偏移 100px。在 animation 属性中调用关键帧声明的动画。