CSS动画制作简易轮播图
1、准备需要展示的内容
2、将要展示图片或内容横排放在一个图片容器.sss里面
3、在图片容器外再加一个展示容器.container,展示容器大小为图片大小
4、给图片容器添加自定义动画,在动画不同阶段设置递增的偏移值
<!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>Document</title>
<style>
.container {
width: 400px;
height: 400px;
overflow: hidden;
}
.sss {
display: flex;
flex-direction: row;
width: 1200px;
height: 400px;
animation: switch 5s ease-out infinite;
}
.sss .box {
width: 400px;
height: 400px;
text-align: center;
font-size: 20px;
font-weight: 700;
}
.box1 {
background-color: red
}
.box2 {
background-color: yellow
}
.box3 {
background-color: blue
}
@keyframes switch {
0%, 25% {
margin: 0;
}
30%, 60% {
margin-left: -400px;
}
70%, 100% {
margin-left: -800px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="sss">
<div class="box box1">
1
</div>
<div class="box box2">
2
</div>
<div class="box box3">
3
</div>
</div>
</div>
</body>
</html>