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

粒子向上持续瀑布动画效果(直接粘贴到记事本改html即可)

代码: 根据个人喜好修改即可

<!DOCTYPE html>
<html lang="zh">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>宽粒子向上效果</title><style>body {margin: 0;overflow: hidden;background-color: black;}canvas {display: block;}</style>
</head>
<body><canvas id="flameCanvas"></canvas><script>const canvas = document.getElementById('flameCanvas');const ctx = canvas.getContext('2d');canvas.width = window.innerWidth;canvas.height = window.innerHeight;class Particle {constructor(x, y) {this.x = x;this.y = y;this.size = Math.random() * 10 + 5; // 粒子大小this.speedY = Math.random() * -4 - 2; // 向上速度this.speedX = (Math.random() - 0.5) * 2; // 水平随机速度this.color = `rgba(255, ${Math.floor(Math.random() * 100) + 155}, 0, 0.8)`; // 橙色this.friction = 0.98; // 摩擦力}update() {this.x += this.speedX;this.y += this.speedY;this.size *= this.friction; // 粒子逐渐变小if (this.size < 0.5) {this.size = 0; // 粒子消失}}draw() {ctx.fillStyle = this.color;ctx.beginPath();ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);ctx.fill();}}class Flame {constructor(x, width) {this.x = x;this.width = width;this.particles = [];this.particleCount = 40; // 每次生成的粒子数量}update() {// 生成新粒子for (let i = 0; i < this.particleCount; i++) {const particleX = this.x + (Math.random() - 0.5) * this.width; // 生成在宽度范围内this.particles.push(new Particle(particleX, canvas.height));}// 更新粒子位置this.particles.forEach((particle, index) => {particle.update();if (particle.size <= 0) {this.particles.splice(index, 1); // 移除消失的粒子}});}draw() {this.particles.forEach(particle => {particle.draw();});}}const flames = [];const flameWidth = canvas.width * 0.6; // 宽度为屏幕的50%// 创建一束宽粒子flames.push(new Flame(canvas.width / 2, flameWidth));function animate() {ctx.clearRect(0, 0, canvas.width, canvas.height);flames.forEach(flame => {flame.update();flame.draw();});requestAnimationFrame(animate);}animate();</script>
</body>
</html>

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 【AI实战攻略】保姆级教程:用AI打造治愈动画vlog,轻松打造爆款,快速涨粉!
  • maxcompute使用篇
  • 8. 防火墙
  • Nginx从入门到入土(二): 学习内容与安装
  • LeetCode 面试经典150题 190.颠倒二进制位
  • 微服务Docker相关指令
  • 第三章 Smart X超融合测试历程第三天
  • 边缘计算网关在工业中的应用
  • ⭐ Unity + OpenCV 实现实时图像识别与叠加效果
  • MySQL---创建数据库(基于SQLyog)
  • MySQL系列—11.Redo log
  • 深度学习速通系列:如何使用文本标注工具进行命名实体识别?
  • 关于http的206状态码和416状态码的意义、断点续传以及CORS使用Access-Control-Allow-Origin来允许跨域请求
  • SpringCloud Alibaba之Seata处理分布式事务
  • Git 推送更改到远程仓库
  • 自己简单写的 事件订阅机制
  • 5分钟即可掌握的前端高效利器:JavaScript 策略模式
  • git 常用命令
  • Git的一些常用操作
  • hadoop集群管理系统搭建规划说明
  • java架构面试锦集:开源框架+并发+数据结构+大企必备面试题
  • Js基础知识(四) - js运行原理与机制
  • magento2项目上线注意事项
  • MyEclipse 8.0 GA 搭建 Struts2 + Spring2 + Hibernate3 (测试)
  • React-生命周期杂记
  • scrapy学习之路4(itemloder的使用)
  • Spark RDD学习: aggregate函数
  • web标准化(下)
  • 阿里云容器服务区块链解决方案全新升级 支持Hyperledger Fabric v1.1
  • 对JS继承的一点思考
  • 关键词挖掘技术哪家强(一)基于node.js技术开发一个关键字查询工具
  • 技术攻略】php设计模式(一):简介及创建型模式
  • 深度解析利用ES6进行Promise封装总结
  • 云大使推广中的常见热门问题
  • mysql面试题分组并合并列
  • 数据可视化之下发图实践
  • # dbt source dbt source freshness命令详解
  • # 职场生活之道:善于团结
  • (bean配置类的注解开发)学习Spring的第十三天
  • (LeetCode 49)Anagrams
  • (笔试题)分解质因式
  • (二)JAVA使用POI操作excel
  • (仿QQ聊天消息列表加载)wp7 listbox 列表项逐一加载的一种实现方式,以及加入渐显动画...
  • (附源码)计算机毕业设计SSM基于健身房管理系统
  • (免费领源码)python+django+mysql线上兼职平台系统83320-计算机毕业设计项目选题推荐
  • (十六)串口UART
  • (转)如何上传第三方jar包至Maven私服让maven项目可以使用第三方jar包
  • (转)用.Net的File控件上传文件的解决方案
  • * 论文笔记 【Wide Deep Learning for Recommender Systems】
  • .Net 8.0 新的变化
  • .NET C# 使用GDAL读取FileGDB要素类
  • .net core webapi Startup 注入ConfigurePrimaryHttpMessageHandler
  • .net 生成二级域名
  • .net安装_还在用第三方安装.NET?Win10自带.NET3.5安装
  • .net遍历html中全部的中文,ASP.NET中遍历页面的所有button控件