CSS3动画 完成两种 轮播图

素材链接:    https://pan.baidu.com/s/1Zdz3p9mRp-Q2e6tbjAaawg

提取码:       ua78

第一种

效果:

源代码:

<!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>

</head>



<body>

    <div class="main">

        <div class="pic">

            <img src="img13/1.jpg" />

            <img src="img13/2.jpg" />

            <img src="img13/3.jpg" />

            <img src="img13/4.jpg" />

        </div>



        <ul>

            <li class="f"></li>

            <li class="s"></li>

            <li class="t"></li>

            <li class="fo"></li>

        </ul>



    </div>

</body>



</html>

<style>

    .main {

        width: 300px;

        /* border: 1px solid red; */

        overflow: hidden;

        position: relative;

    }

    

    .pic {

        width: 1200px;

        font-size: 0;

        animation: lb 16s infinite;

    }

    

    .pic img {

        width: 300px;

    }

    

    ul {

        width: 120px;

        height: 16px;

        position: absolute;

        bottom: 10px;

        text-align: center;

        left: 50px;

    }

    

    li {

        list-style: none;

        float: left;

        width: 16px;

        height: 16px;

        border-radius: 50%;

        background-color: white;

        margin: 6px;

    }

    

    .f {

        animation: f 16s linear infinite;

        animation-delay: 0s;

    }

    

    .s {

        animation: s 16s linear infinite;

        animation-delay: 2s;

    }

    

    .t {

        animation: t 16s linear infinite;

        animation-delay: 6s;

    }

    

    .fo {

        animation: fo 16s linear infinite;

        animation-delay: 10s;

    }

    

    @keyframes lb {

        0%,

        100% {

            transform: translate(0);

        }

        23% {

            transform: translate(-300px);

        }

        46% {

            transform: translate(-600px);

        }

        69% {

            transform: translate(-900px);

        }

        92% {

            transform: translate(0);

        }

    }

    

    @keyframes f {

        0%,

        100% {

            background-color: #777;

        }

        45% {

            background-color: white;

        }

        90% {

            background-color: white;

        }

        95% {

            background-color: #777;

        }

    }

    

    @keyframes s {

        0%,

        100% {

            background-color: #777;

        }

        45% {

            background-color: white;

        }

        90% {

            background-color: white;

        }

        95% {

            background-color: #777;

        }

    }

    

    @keyframes t {

        0%,

        100% {

            background-color: #777;

        }

        45% {

            background-color: white;

        }

        90% {

            background-color: white;

        }

        95% {

            background-color: #777;

        }

    }

    

    @keyframes fo {

        0%,

        100% {

            background-color: #777;

        }

        45% {

            background-color: white;

        }

        90% {

            background-color: white;

        }

        95% {

            background-color: #777;

        }

    }

</style>

第二种

效果图:

源代码:

<!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>css轮播图2</title>
</head>

<body>
    <div class="main">
        <ul class="c1">
            <li class="c1_1 1">

                <img src="img13/1.jpg" alt="">

            </li>
            <li class="c1_1 2">

                <img src="img13/2.jpg" alt="">

            </li>
            <li class="c1_1 3">

                <img src="img13/3.jpg" alt="">

            </li>
            <li class="c1_1 4">

                <img src="img13/4.jpg" alt="">

            </li>
        </ul>
        <div class="c2">
            <span class="dot"></span>
            <span class="dot"></span>
            <span class="dot"></span>
            <span class="dot"></span>
            <span class="dot active"></span>
        </div>
    </div>
</body>

</html>
<style>
    body {
        margin: 0;
        background: #dfe;
    }
    
    ul {
        margin: 0;
        padding: 0;
        list-style: none;
    }
    
    .main {
        position: relative;
        width: 600px;
        height: 300px;
        margin: 100px auto;
        overflow: hidden;
        /* border: solid blue 1px; */
    }
    
    .c1 {
        position: absolute;
        top: 0;
        left: 0;
        width: 2400px;
        height: 100%;
        overflow: hidden;
        animation: img 10s steps(1, end) infinite;
        transition: left 1s linear;
    }
    
    .c1_1 {
        width: 600px;
        height: 100%;
        float: left;
        overflow: hidden;
    }
    
    .c1_1 img {
        display: block;
        width: 100%;
        height: 300px;
        object-fit: cover;
    }
    /* 分页 */
    
    .c2 {
        /* border: 1px red solid; */
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        line-height: 45px;
        background: rgba(255, 255, 255, 0.3);
        text-align: center;
    }
    
    .dot {
        display: inline-block;
        width: 10px;
        height: 10px;
        margin: 0px 5px;
        background: #fff;
        border-radius: 50%;
    }
    /* 橙色小圆点 */
    
    .dot.active {
        position: absolute;
        left: 256px;
        top: 18px;
        width: 11px;
        height: 11px;
        margin: 0;
        background: tomato;
        animation: dot 10s steps(1, end) infinite;
        transition: left 1s linear;
    }
    
    @keyframes img {
        0%,
        100% {
            left: 0;
        }
        25% {
            left: -600px;
        }
        50% {
            left: -1200px;
        }
        75% {
            left: -1800px;
        }
    }
    
    @keyframes dot {
        0%,
        100% {
            left: 257px;
        }
        25% {
            left: 281px;
        }
        50% {
            left: 306px;
        }
        75% {
            left: 331px;
        }
    }
</style>

 

CSS3提供了多种方式来实现图片轮播动画效果,以下是其中一种常见的实现方式: 1. 使用CSS3动画和关键帧(@keyframes)来创建图片轮播效果。首先,需要定义一个包含多个关键帧的动画,每个关键帧对应不同的图片位置或者透明度。然后,将该动画应用到图片元素上。 示例代码如下: ```css /* 定义动画 */ @keyframes slideshow { 0% { opacity: 0; } 20% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } } /* 应用动画 */ .slideshow-container { position: relative; width: 100%; height: 300px; overflow: hidden; } .slideshow-container img { position: absolute; width: 100%; height: 100%; animation: slideshow 10s infinite; } ``` 2. 使用CSS3过渡(transition)来实现图片轮播效果。通过设置不同的过渡效果和延迟时间,可以实现图片的平滑切换。 示例代码如下: ```css .slideshow-container { position: relative; width: 100%; height: 300px; overflow: hidden; } .slideshow-container img { position: absolute; width: 100%; height: 100%; transition: opacity 1s ease-in-out; } .slideshow-container img:first-child { opacity: 1; } .slideshow-container img:not(:first-child) { opacity: 0; } /* 添加过渡效果 */ .slideshow-container:hover img { opacity: 0; } .slideshow-container:hover img:first-child { opacity: 1; } ``` 这只是其中的两种实现方式,还有其他的方法可以实现图片轮播动画效果。你可以根据自己的需求选择适合的方式来实现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值