CSS 3.0实现云雾特效

2020-11-26 11:28:12 浏览数 (1)

给大家分享一个用CSS 3.0实现的云雾特效,效果如下:

以下是代码实现,欢迎大家复制粘贴和收藏。

代码语言:javascript复制
<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>CSS 3.0实现云雾特效</title>
        <style>
            * {
                margin: 0;
                padding: 0;
                box-sizing: border-box;
            }

            .banner {
                position: relative;
                width: 100%;
                height: 100vh;
                background: url(bg.jpg);
                background-size: cover;
                background-position: bottom;
            }

            .banner .clouds {
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                overflow: hidden;
            }

            .banner .clouds img {
                position: absolute;
                bottom: 0;
                max-width: 100%;
                animation: animate calc(8s * var(--i)) linear infinite;
            }

            @keyframes animate {
                0% {
                    transform: translateX(-100%);
                }

                100% {
                    transform: translateX(100%);
                }
            }
        </style>
    </head>

    <body>
        <div class="banner">
            <div class="clouds">
                <img src="cloud1.png" style="--i:1" alt="">
                <img src="cloud2.png" style="--i:2" alt="">
                <img src="cloud3.png" style="--i:3" alt="">
                <img src="cloud4.png" style="--i:4" alt="">
                <img src="cloud5.png" style="--i:5" alt="">
            </div>
        </div>
      
    </body>

</html>

以下是代码中所引用的图片:

0 人点赞