气泡浮动背景特效

首先,定义一个最外层的容器,以及10个气泡标签,结构大致如下:

    <div class="container">
        <div class="bubble"></div>
        <div class="bubble"></div>
        <div class="bubble"></div>
        <div class="bubble"></div>
        <div class="bubble"></div>
        <div class="bubble"></div>
        <div class="bubble"></div>
        <div class="bubble"></div>
        <div class="bubble"></div>
        <div class="bubble"></div>
    </div>

然后就是给最外层的容器设置基本的样式

* {
    padding: 0;
    margin: 0;
}

.container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -999;
    /* 设置渐变背景 */
    background-image: linear-gradient(180deg,rgb(78,168,241),rgb(37,91,241));
}

大致效果如下:

接着就是设置气泡的基本样式以及气泡的动画

.bubble {
    position: absolute;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: inset 0 0 8px #fff;
    /* 设置运动的动画 */
    animation: flutter 10s infinite;
    opacity: 0;
}

/* 定义动画 */
@keyframes flutter {
    0% {
        /* 定义动画  translateX 水平方向移动*/
        transform: translateX(0);
        /* 距离底部的距离 */
        bottom: -100px;
        /* 透明度 */
        opacity: 1;
    }

    50% {
        transform: translateX(100px);
        opacity: .5;
    }

    100% {
        transform: translateX(0);
        bottom: 100%;
        opacity: 0;
    }
}

 

最后就是单独去设置每个气泡的初始位置、大小、动画总时长以及延迟时长

/* 单独设置每个气泡的初始位置、大小、以及动画的延迟时间、完成时间 */
.bubble:nth-child(1) {
    left: -10%;
    width: 50px;
    height: 50px;
    animation-duration: 9s;
    animation-delay: .1s;
}

.bubble:nth-child(2) {
    left: 15%;
    width: 20px;
    height: 20px;
    animation-duration: 6s;
    animation-delay: 1.5s;
}

.bubble:nth-child(3) {
    left: 20%;
    width: 60px;
    height: 60px;
    animation-duration: 9s;
}

.bubble:nth-child(4) {
    left: 30%;
    width: 50px;
    height: 50px;
    animation-duration: 5.5s;
}

.bubble:nth-child(5) {
    left: 40%;
    width: 50px;
    height: 50px;
    animation-duration: 12s;
}

.bubble:nth-child(6) {
    left: 50%;
    width: 20px;
    height: 20px;
    animation-duration: 6s;
    animation-delay: 1s;
}

.bubble:nth-child(7) {
    left: 60%;
    width: 40px;
    height: 40px;
    animation-duration: 8s;
    animation-delay: 1s;
}

.bubble:nth-child(8) {
    left: 65%;
    width: 60px;
    height: 60px;
    animation-duration: 15s;
    animation-delay: 15s;
}

.bubble:nth-child(9) {
    left: 80%;
    width: 55px;
    height: 55px;
    animation-duration: 9s;
    animation-delay: .5s;
}

.bubble:nth-child(10) {
    left: 100%;
    width: 40px;
    height: 40px;
    animation-duration: 12s;
}

源码:

<!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>
    <link rel="stylesheet" href="css/index.css">
</head>
<body>
    <div class="container">
        <div class="bubble"></div>
        <div class="bubble"></div>
        <div class="bubble"></div>
        <div class="bubble"></div>
        <div class="bubble"></div>
        <div class="bubble"></div>
        <div class="bubble"></div>
        <div class="bubble"></div>
        <div class="bubble"></div>
        <div class="bubble"></div>
    </div>
</body>
</html>
* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

.container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -999;
    /* 设置渐变背景 */
    background-image: linear-gradient(180deg,rgb(78,168,241),rgb(37,91,241));
}

.bubble {
    position: absolute;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: inset 0 0 8px #fff;
    /* 设置运动的动画 */
    animation: flutter 10s infinite;
    opacity: 0;
}

/* 定义动画 */
@keyframes flutter {
    0% {
        /* 定义动画  translateX 水平方向移动*/
        transform: translateX(0);
        /* 距离底部的距离 */
        bottom: -100px;
        /* 透明度 */
        opacity: 1;
    }

    50% {
        transform: translateX(100px);
        opacity: .5;
    }

    100% {
        transform: translateX(0);
        bottom: 100%;
        opacity: 0;
    }
}

/* 单独设置每个气泡的初始位置、大小、以及动画的延迟时间、完成时间 */
.bubble:nth-child(1) {
    left: -10%;
    width: 50px;
    height: 50px;
    animation-duration: 9s;
    animation-delay: .1s;
}

.bubble:nth-child(2) {
    left: 15%;
    width: 20px;
    height: 20px;
    animation-duration: 6s;
    animation-delay: 1.5s;
}

.bubble:nth-child(3) {
    left: 20%;
    width: 60px;
    height: 60px;
    animation-duration: 9s;
}

.bubble:nth-child(4) {
    left: 30%;
    width: 50px;
    height: 50px;
    animation-duration: 5.5s;
}

.bubble:nth-child(5) {
    left: 40%;
    width: 50px;
    height: 50px;
    animation-duration: 12s;
}

.bubble:nth-child(6) {
    left: 50%;
    width: 20px;
    height: 20px;
    animation-duration: 6s;
    animation-delay: 1s;
}

.bubble:nth-child(7) {
    left: 60%;
    width: 40px;
    height: 40px;
    animation-duration: 8s;
    animation-delay: 1s;
}

.bubble:nth-child(8) {
    left: 65%;
    width: 60px;
    height: 60px;
    animation-duration: 15s;
    animation-delay: 15s;
}

.bubble:nth-child(9) {
    left: 80%;
    width: 55px;
    height: 55px;
    animation-duration: 9s;
    animation-delay: .5s;
}

.bubble:nth-child(10) {
    left: 100%;
    width: 40px;
    height: 40px;
    animation-duration: 12s;
}

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小白小白从不日白

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值