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

HTML向四周扩散背景

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>扩散背景效果</title><style>body {margin: 0;height: 100vh;display: flex;justify-content: center;align-items: center;background-color: white;overflow: hidden;}button {padding: 10px 20px;font-size: 16px;cursor: pointer;}#overlay {position: fixed;top: 0;left: 0;width: 100%;height: 100%;background-color: black;opacity: 0;pointer-events: none;z-index: 100;}#circle {position: fixed;top: 50%;left: 50%;width: 0;height: 0;background-color: black;border-radius: 50%;transform: translate(-50%, -50%);z-index: 101;}</style></head><body><button id="toggleBtn">点击切换背景</button><div id="overlay"></div><div id="circle"></div><script src="script.js"></script></body><script>document.addEventListener("DOMContentLoaded", () => {const toggleBtn = document.getElementById("toggleBtn");const overlay = document.getElementById("overlay");const circle = document.getElementById("circle");let isAnimating = false;toggleBtn.addEventListener("click", () => {if (!isAnimating) {isAnimating = true;// 开始扩散动画let radius = 0;const maxRadius = Math.sqrt(window.innerWidth * window.innerWidth +window.innerHeight * window.innerHeight);const animate = () => {if (radius < maxRadius) {radius += 5;circle.style.width = `${radius * 2}px`;circle.style.height = `${radius * 2}px`;animate();} else {// 扩散完成后,显示黑色背景overlay.style.opacity = "1";circle.style.opacity = "0";isAnimating = false;}};animate();}});});</script>
</html>

相关文章:

  • DriveGenVLM:基于视觉-语言模型的自动驾驶真实世界视频生成
  • C#中的ThreadStart委托
  • 代理IP高可用性与稳定性方案:负载均衡、节点健康监测与智能切换策略
  • LLaMA-Factory:了解webUI参数
  • 【hive】hive内存dump导出hprof文件
  • 虚幻引擎5-Unreal Engine笔记之什么时候新建GameMode,什么时候新建关卡?
  • solidity智能合约-知识点
  • 开源音视频转文字工具:基于 Vosk 和 Whisper 的多语言语音识别项目
  • B/S架构和C/S架构的介绍与分析
  • 如何在LVGL之外的线程更新UI内容
  • 从纸质契约到智能契约:AI如何改写信任规则与商业效率?​——从智能合约到监管科技,一场颠覆传统商业逻辑的技术革命
  • Unreal 从入门到精通之SceneCaptureComponent2D实现UI层3D物体360°预览
  • 学习VS2022离线安装包的下载方法
  • STC-ISP烧录过程中一直显示“正在检测单片机”的解决办法
  • WebSphere Application Server(WAS)8.5.5教程第五讲
  • 解释加密中的加盐操作
  • 理解PostgreSQL查询执行计划(三)--复杂操作篇
  • C++17之std::launder函数
  • 【回溯法】0-1背包问题 C/C++(附代码)
  • nmcli connection reload
  • 戛纳参赛片《爱丁顿》评论两极,导演:在这个世道不奇怪
  • “十五五”时期长三角需创新机制,形成高水平一体化合作路径
  • 媒体评教师拎起学生威胁要扔下三楼:师风师德不能“悬空”
  • 人民网:激发博物馆创新活力,让“过去”拥有“未来”
  • 国宝文物子弹库帛书二、三卷从美启程,18日凌晨抵京
  • 女排奥运冠军宋妮娜:青少年保持身心健康才能走得更远