animation实现轮播图 - 青蓝鱼的博客-没有bug的代码是不完美的
侧边栏壁纸
  • 累计撰写 27 篇文章
  • 累计收到 16 条评论
css

animation实现轮播图

admin
2022-04-30 / 0 评论 / 151 阅读 / 正在检测是否收录...

第一步定义html结构

<div class="imgs">
    <img src="./imgs/204071.jpg" alt="">
    <img src="./imgs/493016.png" alt="">
    <img src="./imgs/810967.jpg" alt="">
    <img src="./imgs/974914.png" alt="">
    <img src="./imgs/974921.png" alt="">
</div>

第二部定义css样式

<style>
        @keyframes bannerMove {
            0% {
                opacity: 0;
                z-index: 2;
            }
            5% {
                opacity: 1;
                z-index: 2;
            }
            20% {
                opacity: 1;
                z-index: 2;
            }
            25% {
                opacity: 1;
                z-index: 0;
            }
            50% {
                opacity: 0;
                z-index: 0;
            }
            100% {
                opacity: 0;
                z-index: 0;
            }
        }
        
        .imgs {
            position: relative;
            left: 25%;
            transition: opacity 0.5s ease 0s;
        }
        
        .imgs>img {
            position: absolute;
            width: 800px;
            height: 450px;
            margin: auto;
            animation-name: bannerMove;
            animation-duration: 20s;
            animation-timing-function: step-end;
            animation-iteration-count: infinite;
        }
        
        .imgs>img:nth-of-type(2) {
            animation-delay: 4s;
        }
        
        .imgs>img:nth-of-type(3) {
            animation-delay: 8s;
        }
        
        .imgs>img:nth-of-type(4) {
            animation-delay: 12s;
        }
        
        .imgs>img:nth-of-type(5) {
            animation-delay: 16s;
        }
    </style>

第三,实现效果如下图:

gif

本文共 23 个字数,平均阅读时长 ≈ 1分钟
0

打赏

评论 (0)

取消