animation: ;
关键针动画 简写属性
需要配合@keyframes 使用
animation:
animation-name:执行动画名
animation-duration:执行动画的总时间 假设为4秒 设置的4帧的动画 没针执行的时间为 总时间/多少帧 4/4 也就是1秒
animation-timing-function:动画速度曲线
ease(默认值) 慢-》 快-》慢<br /> linear 匀速的<br /> ease-in 慢速开始 慢-》快<br /> ease-out 慢速结束 快-》慢<br /> ease-in-out: 慢-》快-》慢<br /> cubic-bezier() 也可以设置贝塞尔曲线<br />steps() 会取消过度效果<br />edn 保留当前帧状态,直到这段动画时间结束<br />start 保留下一帧状态,直到这段动画时间结束<br /> <br /> animation-delay 动画的延迟时间<br /> 可以为负值 负值代表的是动画立即触发 并且跳过多少秒执行<br /> animation-iteration-count : 动画执行的次数<br /> infinite 无休止的运动<br /> animation-direction 动画运动的方向 是否做往返运动<br /> normal正常的0% - 100%<br /> reverse 反向的运动 100% - 0%<br /> alternate 正常的往返运动<br /> alternate-reverse 反向的往返运动<br /> animation-fill-mode 动画在静止状态的样式<br /> forwards: 动画停止在最后一个关键帧的位置 假设动画开始前背景色为红色,最后一帧的动画让其颜色为黑色,默认情况下动画执行完成回复原来的样子,设置这个属性会让其保留在最后一帧的样式<br /> backwards: 代表动画第一个关键帧立即作用 假设动画没开始前背景色为红色,第一帧的动画让其颜色变为黑色,这个属性会直接让其元素保留在第一帧动画的样式,也就背景色提前变为黑色<br /> both: 代表的是动画第一个关键帧立即作用并且动画停止在最后一个关键帧的位置<br /> animation: 关键帧动画 设置了就会立即的去执行 不关注子属性顺序的 <br /> 但是其中的动画执行时间和动画延迟时间相对顺序是不能变得<br /> 可以设置多个动画同时执行用“,”隔开
@keyframes
@keyframes里有两种写法 一种是百分数 另一种使用from代替0% to代替100% 除此之外没有其他写法
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>@keyframes move{0%{left: 0;top: 0;}25%{left: 100px;top: 0;}50%{left: 100px;top: 100px;}75%{left: 0;top: 100px;}100%{left: 0;top: 0;}}@keyframes cor{from{background: black;}50%{background: blue;}to{background: blueviolet;}}div{position: absolute;width: 100px;height: 100px;background: red;animation: move 4s linear 5s infinite , cor 3s linear infinite;}</style></head><body><div></div></body></html>
step练习
打字效果
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>@keyframes cursor{0%{border-left-color: rgba(0, 0, 0, 0);}50%{border-left-color: rgba(0, 0, 0, 1);}100%{border-left-color: rgba(0, 0, 0, 0);}}@keyframes cover{0%{left: 0;}100%{left: 100%;}}div{height: 100px;display: inline-block;font-size: 100px;line-height: 100px;font-family: monospace;position: relative;background-color: #f10;}div::after{content: "";position: absolute;height: 90px;width: 100%;background: #fff;left: 0;top: 10px;border-left: 2px solid #000;animation: cursor 1s steps(1,end) infinite , cover 5s steps(5,end) forwards;}</style></head><body><div>asdff</div></body></html>
钟表效果
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>@keyframes second {0% {transform: rotate(180deg);}100% {transform: rotate(540deg);}}@keyframes minute {0% {transform: rotate(180deg);}100% {transform: rotate(540deg);}}@keyframes hour {0% {transform: rotate(180deg);}100% {transform: rotate(540deg);}}.clock {width: 512px;height: 512px;background: url(/img/clock.png);background-size: cover;background-repeat: no-repeat;position: relative;}.second {width: 16px;height: 278px;background: url(/img/second.png);background-size: cover;background-repeat: no-repeat;position: absolute;left: 247px;top: 180px;z-index: 3;transform-origin: center 76px;transform: rotate(180deg);animation: second 60s steps(60, end) infinite;}.minute {width: 32px;height: 218px;background: url(/img/minute.png);background-size: cover;background-repeat: no-repeat;position: absolute;left: 238px;top: 240px;z-index: 2;transform-origin: center 16px;transform: rotate(180deg);animation: minute 3600s steps(60, end) infinite;}.hour {width: 32px;height: 148px;background: url(/img/hour.png);background-size: cover;background-repeat: no-repeat;position: absolute;left: 238px;top: 240px;z-index: 1;transform-origin: center 16px;transform: rotate(180deg);animation: hour 43200s steps(12,end) infinite;}</style></head><body><section class="clock"><div class="second"></div><div class="minute"></div><div class="hour"></div></section></body></html>
跑马效果
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>@keyframes run{0%{background-position: 0 0;}100%{background-position: -2400px 0;}}.horse{width: 200px;height: 100px;background: url(/img/horse.png);background-position: 0 0;background-repeat: no-repeat;animation: run .5s steps(12,end) infinite;}</style></head><body><div class="horse"></div></body></html>
stop所需的图片资源 ⬇
img.rar
