当前位置: 首页 > article >正文

CSS\JS实现页面背景气泡logo上浮效果

效果图:

单容器显示气泡:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bubble Logo Animation</title>

</head>
<body>
    <div class="bubble-container">
        <!-- 气泡将会动态添加到这里 -->
    </div>


</body>



<style>
body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #ffffff; /* 背景颜色 */
    display: flex;
    justify-content: center;
    align-items: center;
}

.bubble-container {
    position: relative;
    width: 100%;
    height: 100%;
}

.bubble {
    position: absolute;
    bottom: -50px; /* 从页面底部开始 */
    width: 100px;
    height: 100px;
    opacity: 0.8;
    animation: floatUp 10s infinite;
}

.bubble img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* 气泡上浮动画 */
@keyframes floatUp {
    0% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateY(-100vh) scale(1.2);
        opacity: 0;
    }
}


</style>

<script>
const bubbleContainer = document.querySelector('.bubble-container');

function createBubble() {
    const bubble = document.createElement('div');
    bubble.className = 'bubble';
    bubble.style.left = `${Math.random() * 100}vw`; // 随机水平位置
    bubble.style.animationDuration = `${5 + Math.random() * 5}s`; // 随机动画时长
    bubble.innerHTML = `<img src="https://img-home.csdnimg.cn/images/20201124032511.png" alt="Logo">`;

    bubbleContainer.appendChild(bubble);

    // 动画结束后移除气泡
    bubble.addEventListener('animationend', () => {
        bubble.remove();
    });
}

// 定期生成新的气泡
setInterval(createBubble, 1000);


</script>
</html>

全屏显示气泡:


  <div class="one" style="width: 100%;height: 300px;background-color: pink;">

  </div>

    <div class="bubble-container">
        <!-- 气泡将会动态添加到这里 -->
    </div>




    <style>
        .one {
            width: 100%;
            height: 300px;
            background-color: pink;
            z-index: 1;
            position: relative;
        }

        /* 覆盖整个页面的气泡容器 */
        .bubble-container {
            position: fixed; /* 使容器固定在页面上 */
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none; /* 确保气泡不影响页面其他内容的交互 */
            z-index: 9999; /* 将气泡放在最前面 */
        }

        .bubble {
            position: absolute;
            bottom: -50px;
            width: 75px;
            height: 75px;
            opacity: 0.5;
            animation: floatUp 10s infinite;
        }

        .bubble img {
            width: 100%;
            height: 100%;
            object-fit: contain;
        }

        /* 气泡上浮动画 */
        @keyframes floatUp {
            0% {
                transform: translateY(0) scale(1);
                opacity: 0.8;
            }
            100% {
                transform: translateY(-100vh) scale(1.2);
                opacity: 0;
            }
        }
    </style>

<script>
const bubbleContainer = document.querySelector('.bubble-container');

function createBubble() {
    const bubble = document.createElement('div');
    bubble.className = 'bubble';
    bubble.style.left = `${Math.random() * 100}vw`; // 随机水平位置
    bubble.style.animationDuration = `${5 + Math.random() * 5}s`; // 随机动画时长
    bubble.innerHTML = `<img src="https://img-home.csdnimg.cn/images/20201124032511.png" alt="Logo">`;

    bubbleContainer.appendChild(bubble);

    // 动画结束后移除气泡
    bubble.addEventListener('animationend', () => {
        bubble.remove();
    });
}

// 定期生成新的气泡
setInterval(createBubble, 5000);


</script>


http://www.kler.cn/a/281121.html

相关文章:

  • Python--安装netCDF4/读取nc文件
  • 代码随想录算法训练营第五十二天 | 图论part03
  • 【设计模式】模块模式和桥接模式
  • TCP Analysis Flags 之 TCP ACKed unseen segment
  • 论文阅读与源码解析:CMX
  • 【亚马逊云】注册登录AWS 合作伙伴网络(APN)操作流程
  • 模型 麦肯锡七步成诗法
  • Vue 0_1项目实战
  • 深度学习实用方法 - 选择超参数篇
  • 使用Python实现深度学习模型:智能森林火灾预警系统
  • CSS系列之详解overflow(四)
  • C# 对桌面快捷方式的操作设置开机启动项
  • 经验笔记:Token、Session、Cookie 及密码级别安全存储
  • Leetcode面试经典150题-188.买卖股票的最佳时机IV
  • Unity 编辑器-UGUI拓展Button,一个和原Button一样按钮⭐
  • Linux 系统收发网络包
  • 三丰云免费服务器
  • TCP,UDP,wireshark抓包
  • Nginx正向代理和反向代理的区别
  • Shell 编程之正则表达式与文本处理器