动画
随着时间的推移动态的改变css的样式属性
(1)语法【组成】
animation 动画的配置
@keyframes 动画的关键帧
(2)属性 例如:
/* 动画的名称 */
animation-name: move;
/* 动画持续的时间 */
animation-duration: 1s;
/* 动画的填充模式 当前div在动画结束时显示的位置
forwards 元素在动画最后一帧的位置显示
backwords 元素在动画结束后回到开始的位置【默认值】
前提:动画的执行次数是有限的
*/
animation-fill-mode: forwards;
/* 动画执行次数 */
animation-iteration-count: 2;
/* 动画的速度
linear 匀速
ease 先快后慢
ease-in 先慢后快 */
animation-timing-function: linear;
/* 动画的延迟时间 */
animation-delay: 2s;
/* 动画的方向 */
animation-direction: alternate;
/* 速写 */
/* animation: move duration timing-function delay iteration-count direction fill-mode; */
/* 动画的状态
pasued 暂停
running 执行 */
animation-play-state: paused;
/* 1、动画的定义
@keyframes css固定语法
move 动画的名称,可以自定义
from 动画的开始时间
to 动画的结束时间
*/
@keyframes move {
from{
left: 0;
}
to{
left: calc(100% - 100px);;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>轮播图</title>
</head>
<style>
.eye {
width: 400px;
height: 300px;
border: 1px solid #333;
margin: 100px auto;
overflow: hidden;
}
.wrap {
width: 1600px;
height: 300px;
margin-left: -400px;
animation: move 4s infinite steps(4);
}
.item {
width: 400px;
height: 300px;
float: left;
}
@keyframes move {
from {
margin-left: 0px;
}
to {
margin-left: -1600px;
}
}
</style>
<body>
<div class="eye">
<div class="wrap">
<div class="item" style="background-color: darkorange;">1</div>
<div class="item" style="background-color: blueviolet;">2</div>
<div class="item" style="background-color: brown;">3</div>
<div class="item" style="background-color: cornflowerblue;">4</div>
</div>
</div>
</body>
</html>