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

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>
http://www.lryc.cn/news/2379973.html

相关文章:

  • 基于Java在高德地图面查询检索中使用WGS84坐标的一种方法-以某商场的POI数据检索为例
  • 使用 Terraform 创建 Azure Databricks
  • 本地部署dify+ragflow+deepseek ,结合小模型实现故障预测,并结合本地知识库和大模型给出维修建议
  • SECERN AI提出3D生成方法SVAD!单张图像合成超逼真3D Avatar!
  • 深入探索:Core Web Vitals 进阶优化与新兴指标
  • c/c++的opencv开闭操作
  • 【物联网】 ubantu20.04 搭建L2TP服务器
  • winrar 工具测试 下载 与安装
  • PLC组网的方法、要点及实施全解析
  • 网络安全深度解析:21种常见网站漏洞及防御指南
  • 【FAQ】HarmonyOS SDK 闭源开放能力 —Vision Kit (3)
  • Java大厂面试实战:Spring Boot与微服务场景中的技术点解析
  • 从零启动 Elasticsearch
  • 比较两个用于手写体识别的卷积神经网络(CNN)模型
  • Linux利用多线程和线程同步实现一个简单的聊天服务器
  • 【计网】作业5
  • 15、Python布尔逻辑全解析:运算符优先级、短路特性与实战避坑指南
  • Nginx基础知识
  • Vue-监听属性
  • python fastapi + react, 写一个图片 app
  • nginx集成防火墙ngx_waf的docker版
  • vscode c++编译onnxruntime cuda 出现的问题
  • sts下载安装
  • 中服云生产线自动化智能化调度生产系统:打造智能制造新标杆
  • next.js实现项目搭建
  • Redisson 四大核心机制实现原理详解
  • 云鼎入鼎系统:一站式电商管理解决方案
  • Leetcode134加油站
  • 关于Android Studio for Platform的使用记录
  • Linux的内存泄漏问题及排查方法