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

2024-08-25 20:44

本文主要是介绍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>

这篇关于CSS\JS实现页面背景气泡logo上浮效果的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1106614

相关文章

Vue3 的 shallowRef 和 shallowReactive:优化性能

大家对 Vue3 的 ref 和 reactive 都很熟悉,那么对 shallowRef 和 shallowReactive 是否了解呢? 在编程和数据结构中,“shallow”(浅层)通常指对数据结构的最外层进行操作,而不递归地处理其内部或嵌套的数据。这种处理方式关注的是数据结构的第一层属性或元素,而忽略更深层次的嵌套内容。 1. 浅层与深层的对比 1.1 浅层(Shallow) 定义

JS常用组件收集

收集了一些平时遇到的前端比较优秀的组件,方便以后开发的时候查找!!! 函数工具: Lodash 页面固定: stickUp、jQuery.Pin 轮播: unslider、swiper 开关: switch 复选框: icheck 气泡: grumble 隐藏元素: Headroom

这15个Vue指令,让你的项目开发爽到爆

1. V-Hotkey 仓库地址: github.com/Dafrok/v-ho… Demo: 戳这里 https://dafrok.github.io/v-hotkey 安装: npm install --save v-hotkey 这个指令可以给组件绑定一个或多个快捷键。你想要通过按下 Escape 键后隐藏某个组件,按住 Control 和回车键再显示它吗?小菜一碟: <template

【 html+css 绚丽Loading 】000046 三才归元阵

前言:哈喽,大家好,今天给大家分享html+css 绚丽Loading!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕 目录 📚一、效果📚二、信息💡1.简介:💡2.外观描述:💡3.使用方式:💡4.战斗方式:💡5.提升:💡6.传说: 📚三、源代码,上代码,可以直接复制使用🎥效果🗂️目录✍️

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

【Prometheus】PromQL向量匹配实现不同标签的向量数据进行运算

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全栈,前后端开发,小程序开发,人工智能,js逆向,App逆向,网络系统安全,数据分析,Django,fastapi

如何在页面调用utility bar并传递参数至lwc组件

1.在app的utility item中添加lwc组件: 2.调用utility bar api的方式有两种: 方法一,通过lwc调用: import {LightningElement,api ,wire } from 'lwc';import { publish, MessageContext } from 'lightning/messageService';import Ca

让树莓派智能语音助手实现定时提醒功能

最初的时候是想直接在rasa 的chatbot上实现,因为rasa本身是带有remindschedule模块的。不过经过一番折腾后,忽然发现,chatbot上实现的定时,语音助手不一定会有响应。因为,我目前语音助手的代码设置了长时间无应答会结束对话,这样一来,chatbot定时提醒的触发就不会被语音助手获悉。那怎么让语音助手也具有定时提醒功能呢? 我最后选择的方法是用threading.Time