制作思路

将轮播图分为三个部分,分别为视口区,滚动区和图片。
1、视口区。即可看见图片的地方,将其固定不动。
2、滚动区。该区域需要产生图片轮流出现的效果,因而需要给此区域添加动画效果。宽度为所有图片的总长度。
3、图片。放置图片的地方。

代码

<!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>
        *{
            margin: 0;
            padding: 0;
        }
        .outer{
            width: 700px;
            height: 300px;
            border: 0 solid black;
            overflow: hidden;
            /*将超出outer部分隐藏*/
            margin: 200px auto;
        }
        .center{
            width: 2100px;
            height: 300px;
            animation-name: move;
            animation-duration: 6s;
            /*确定每张图片出现时可用时长*/
            animation-timing-function: steps(3);
            /*使用steps可以使图片一张一张出现*/
            animation-iteration-count: infinite;
            /*infinite使图片循环播放*/
        }
        .center div{
            width: 700px;
            height: 300px;
            float: left;
            background-color: blue;
        }
        .center div:nth-child(2){
            background-color: red;
        }
        .center div:last-child{
            background-color: pink;
        }
        @keyframes move{
            from{
                margin-left: 0;
            }
            to{
                margin-left: -2100px;
            }
        }
        /*最后只需在第三级的div中加入图片即可*/
    </style>
</head>
<body>
    <div class="outer">
        <div class="center">
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
</body>
</html>

更多推荐

网站中轮播图的制作方法