中秋节快乐简单html页面

news/2024/9/20 1:08:04/文章来源:https://www.cnblogs.com/brian-sun/p/18413773
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>中秋快乐</title>
<style>@font-face {font-family: 'HeiTi';src: url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@900&display=swap');}body, html {margin: 0;padding: 0;overflow: hidden;background: url('zhongqiu1.jpg') no-repeat center center fixed;background-size: cover;}canvas {display: block;}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script>const canvas = document.getElementById('canvas');const ctx = canvas.getContext('2d');canvas.width = window.innerWidth;canvas.height = window.innerHeight;const backgroundImage = new Image();backgroundImage.src = 'zhongqiu1.jpg';let backgroundLoaded = false;backgroundImage.onload = () => {ctx.drawImage(backgroundImage, 0, 0, canvas.width, canvas.height);backgroundLoaded = true;};class Spark {constructor(x, y, speedX, speedY, color) {this.x = x;this.y = y;this.speedX = speedX;this.speedY = speedY;this.color = color;this.alpha = 1;this.fade = 0.02;}update() {this.x += this.speedX;this.y += this.speedY;this.speedX *= 0.98;this.speedY *= 0.98;this.speedY += 0.1; // gravitythis.alpha -= this.fade;}draw() {ctx.save();ctx.globalAlpha = this.alpha;ctx.beginPath();ctx.arc(this.x, this.y, 2, 0, Math.PI * 2);ctx.fillStyle = this.color;ctx.fill();ctx.restore();}}class Firework {constructor(x, y, targetX, targetY) {this.x = x;this.y = y;this.targetX = targetX;this.targetY = targetY;this.sparks = [];this.exploded = false;this.speed = 2;this.color = this.randomColor();}randomColor() {const r = Math.floor(Math.random() * 256);const g = Math.floor(Math.random() * 256);const b = Math.floor(Math.random() * 256);return `rgb(${r}, ${g}, ${b})`;}update() {if (!this.exploded) {const dx = this.targetX - this.x;const dy = this.targetY - this.y;const distance = Math.sqrt(dx * dx + dy * dy);if (distance < 5) {this.exploded = true;for (let i = 0; i < 100; i++) {const angle = Math.random() * 2 * Math.PI;const speed = Math.random() * 5;const sparkX = this.x;const sparkY = this.y;const sparkSpeedX = Math.cos(angle) * speed;const sparkSpeedY = Math.sin(angle) * speed;this.sparks.push(new Spark(sparkX, sparkY, sparkSpeedX, sparkSpeedY, this.randomColor()));}} else {this.x += dx / distance * this.speed;this.y += dy / distance * this.speed;}} else {this.sparks.forEach(spark => spark.update());this.sparks = this.sparks.filter(spark => spark.alpha > 0);}}draw() {if (!this.exploded) {ctx.beginPath();ctx.arc(this.x, this.y, 3, 0, Math.PI * 2);ctx.fillStyle = this.color;ctx.fill();} else {this.sparks.forEach(spark => spark.draw());}}}const fireworks = [];setInterval(() => {const x = Math.random() * canvas.width;const y = canvas.height;const targetX = Math.random() * canvas.width;const targetY = Math.random() * canvas.height / 2;fireworks.push(new Firework(x, y, targetX, targetY));}, 500);function drawMoon() {const moonX = canvas.width - 150; // 调整X坐标const moonY = 150; // 调整Y坐标const moonRadius = 50;ctx.beginPath();ctx.arc(moonX, moonY, moonRadius, 0, Math.PI * 2);ctx.fillStyle = 'yellow';ctx.fill();}let textAngle = 0;<!-- const colors = ['red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple']; -->const colors = ['red', 'orange', 'yellow'];let colorIndex = 0;function updateTextColor() {colorIndex = (colorIndex + 1) % colors.length;}setInterval(updateTextColor, 1000); // 每1秒更新一次颜色function drawText() {const text = '中秋节快乐';ctx.font = '96px "仿宋"'; // 增大字体大小,并加粗ctx.textAlign = 'center';const textX = canvas.width / 2;const textY = canvas.height / 2;// 计算文本宽度和高度const metrics = ctx.measureText(text);const textWidth = metrics.width;const textHeight = 96; // 字体大小// 绘制半透明的白色矩形背景ctx.save();ctx.globalAlpha = 0.09; // 设置透明度ctx.fillStyle = 'white';ctx.fillRect(textX - textWidth / 2 - 20, textY - textHeight / 2 - 60, textWidth + 60, textHeight + 60);ctx.restore();// 绘制晃动的文字ctx.save();ctx.translate(textX, textY);ctx.rotate(Math.sin(textAngle) * 0.1); // 以底部为圆心左右晃动ctx.translate(-textX, -textY);ctx.fillStyle = colors[colorIndex];ctx.fillText(text, textX, textY);ctx.restore();textAngle += 0.05; // 调整晃动速度}function animate() {if (backgroundLoaded) {// 绘制半透明黑色背景,保留烟花拖尾效果ctx.globalAlpha = 0.1;ctx.fillStyle = 'black';ctx.drawImage(backgroundImage, 0, 0, canvas.width, canvas.height);ctx.fillRect(0, 0, canvas.width, canvas.height);ctx.globalAlpha = 1;fireworks.forEach(firework => {firework.update();firework.draw();});drawMoon();drawText();}requestAnimationFrame(animate);}animate(); // 启动动画循环
</script>
</body>
</html>

然后把zhongqiu1.jpg替换成自己的,和html放在一个目录下,效果如下:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/796979.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

专业角度深入讲解:大模型备案(生成式人工智能)

一、什么是大模型备案? 大模型备案是指大模型产品在向公众开放及商用之前,经过国家互联网信息办公室(简称“网信办”)等监管部门的备案审批过程。 是为加强生成式人工智能服务的合规管理,通过备案制度,促进人工智能技术的健康发展,建立起一个既安全又可靠的人工智能服务…

PbootCMS怎么调用网站的留言数和文章总数

在 PBootCMS 中,可以使用 pboot:sql 标签来自定义任意查询语句并循环输出。下面详细介绍如何使用此标签来调用网站的留言数和文章总数。 1. 调用网站的留言数 示例代码html{pboot:sql sql="select count(id) as total from ay_message"}留言合计:[sql:total]条 {/p…

Github数据泄露事件处置常见技巧

手动获取个人邮箱 方法一:通过commits找到作者提交的,点击箭头位置在出现的url后面加上.patch https://github.com/xxxx/xxxexample/commit/4a0b0613da9ca66c61bc9e8eeebe7325c4908afeb 修改后的 https://github.com/xxxx/xxxexample/commit/4a0b0613da9ca66c61bc9e8eeebe732…

2024年9月中国数据库排行榜:openGauss系多点开花,根社区优势明显

本文解读墨天轮数据库流行度排行榜,从产业格局视角梳理行业发展走向,开源势力力争上游、阿里华为两极鼎立云上云下各争先,欢迎一起阅读交流!在墨天轮发布的9月中国数据库流行度排行榜中,中国数据库产业格局进一步聚集刷新,呈现出3大显著特征:开源势力力争上游显优势领先…

PbootCMS模板自动生成当前页面二维码

在 PBootCMS 中,qrcode 标签用于生成对应文本的二维码图片。这对于产品列表页或详情页为每个产品生成二维码非常有用。以下是详细的使用说明和示例代码。 1. qrcode 标签的基本用法 参数说明string=*:指定生成二维码的文本内容。2. 示例代码 生成产品详情页的二维码 假设你需…

PbootCMS会员相关标签调用

在 PBootCMS 中,你可以通过一系列会员相关的标签来实现会员管理功能。以下是对这些标签的具体说明和使用方法: 1. 基本标签 标签说明{pboot:ucenter}:个人中心地址 {pboot:login}:登录地址 {pboot:register}:注册地址 {pboot:umodify}:资料修改地址 {pboot:logout}:退出…

PbootCMS首页调用公司简介等频道内容

在 PBootCMS 中,调用专题频道内容(如公司简介、联系我们等)可以通过 content 标签来实现。以下是具体的使用方法和示例代码: 1. content 标签的基本用法 参数说明id:文章内容或专题内容对应的 ID。 scode:栏目管理中该栏目的 ID。示例代码html{pboot:content id=1}[conte…

深度解读:Spring.3版本自动装配机制的演变与实践

在今天的讲解中,我们从Spring-AI的源码出发,逐步解构了自动装配的演变与实践。虽然自动装配的核心概念自以往并无太大改变,但Spring Boot 3.3.x版本带来的机制调整,确实值得我们重新审视。通过回顾新版的自动装配实现方式,我们不仅加深了对新机制的理解,也为后续的源码分…

Qt自定义插件plugin的开发和调用

1.需求描述 设备管理组件保存了设备信息和通道信息到sqlite数据库,其他组件也想要访问这个数据库中的内容;需要开发一个自定义插件,用于提供接口给其他组件访问数据库;开发环境vs2015+Qt5.9.6 2.插件介绍 插件主要面向接口编程,通过接口实现功能的扩展,而不需要访问.lib文…

SCM信道模型和SCME信道模型的matlab特性仿真,对比空间相关性,时间相关性,频率相关性

1.算法仿真效果 matlab2022a仿真结果如下(完整代码运行后无水印): 由仿真结果可以看出:信道时间相关性随着时间间隔的增大而减小,同一个天线间隔下,宏小区与微小区的间相关性相同,因为这两种场景的AOA产生方法相同,也反映出该信道模型不够准确。同理,频率相关性,空间…

升压斩波电路的simulink建模与仿真

1.课题概述 升压斩波电路的simulink建模与仿真,通过双闭环结构实现电池,点击的控制。2.系统仿真结果3.核心程序与模型 版本:MATLAB2022a 4.系统原理简介升压斩波电路(Boost Chopper Circuit)是一种电力电子转换电路,主要用于将输入直流电压升高到更高的直流电压水平。该电…