通过动画可以实现一些更加复杂的交互效果
它不用等待触发事件
可以自动播放
animation简写
animation: name 400ms steps(6) alternate-reverse infinite;
@keyframes
指定动画每一步执行的位置
这里的to和from应该是同属性切换
@keyframes name{
from{}
to{}
}
@keyframes name{
0%{}
50%{}
100%{}
}
from
to
指定动画的结束位置
animation-name
指定动画的名字
animation-duration
指定动画持续的时间
animation-delay
动画的延迟
animation-timing-function
steps()
steps(2,end)
有几个图片的写几步
@keyfram写图片的最后一个位置
@keyframes name{
0%{
background-position: 0 0;
}
100%{
background-position: (这里图片多宽就写多少)-3000px 0;
}
}
animation-iteration-count
infinite
表示循环执行
.box1{
height: 271px;
width: calc(528px / 4);
background-image: url(image/1.png);
margin: 0 auto;
background-position: 0 0;
animation-name: name;
animation-duration: 400ms;
animation-delay:3s;
animation-timing-function:steps(3,end);
animation-iteration:infinite;
}
@keyframes name{
from{
background-position: 0 0;
}
to{
background-position: calc(-528px / 4 * 3) 0;
}
}
animation-play-state
paused
running
动画运行
默认值
animation-direction
normal
reverse
alternate
alternate-reverse
反向交替