用HTML5+CSS+JavaScript庆祝国庆

server/2024/10/20 5:47:35/

用HTML5+CSS+JavaScript庆祝国庆

中华人民共和国的国庆日是每年的10月1日。

1949年10月1日,中华人民共和国中央人民政府成立,在首都北京天安门广场举行了开国大典,中央人民政府主席毛泽东庄严宣告中华人民共和国成立,并亲手升起了第一面五星红旗。这一历史性的时刻标志着新中国的诞生。1949年12月2日,中央人民政府委员会第四次会议接受全国政协的建议,通过了《关于中华人民共和国国庆日的决议》,决定每年10月1日为中华人民共和国国庆日。

国庆日这一天,全国各地都会举行各种庆祝活动,如悬挂国旗、唱国歌、文艺演出、烟花表演等方式来庆祝这一重要节日。

现在,让我们用HTML5+CSS+JavaScript庆祝中华人民共和国的国庆日。

先看用css3画五星红旗效果:

css3画五星红旗源码如下:

<!DOCTYPE HTML>
<html>
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>CSS画五星红旗</title><style>.flag{width: 300px;height: 200px;background-color: red;position: relative;}body {display: flex;height: 100vh; /* 页面高度 */justify-content: center; /* 水平居中 */align-items: center; /* 垂直居中 */margin: 0; /* 去掉默认边距 */}.star{margin: 0 0;position: absolute;display: block;/* color: red; */width: 0;height: 0;border-right: 100px solid transparent;border-bottom: 70px solid yellow;/* */border-left: 100px solid transparent;transform: rotate(35deg);left: 20px;}.star:before {border-bottom: 80px solid yellow;border-left: 30px solid transparent;border-right: 30px solid transparent;position: absolute;height: 0;width: 0;top: -45px;left: -65px;display: block;content: '';transform: rotate(-35deg);}.star:after{content: '';margin: 0;position: absolute;display: block;/* color: red; */width: 0;height: 0;border-right: 100px solid transparent;border-bottom: 70px solid yellow;/* */border-left: 100px solid transparent;transform: rotate(-70deg);left: -107px;top: 5px;}.big{/* position: absolute; */transform: scale(.3) rotate(35deg);top: 10px;left: -50px;z-index: 3;}.little1{position: absolute;transform: scale(.1) rotate(-60deg);top: -15px;left: 5px;}.little2{position: absolute;transform: scale(.1) rotate(-45deg);top: 5px;left: 30px;}.little3{position: absolute;transform: scale(.1) rotate(35deg);top: 33px;left: 30px;}.little4{position: absolute;transform: scale(.1) rotate(60deg);top: 50px;left: 5px;}</style></head> 
<body><div class="flag"><div class="star big"></div><div class="star little1"></div><div class="star little2"></div><div class="star little3"></div><div class="star little4"></div></div>
</body>
</html>

下面添加烟花效果烘托国庆气氛

先看国庆烟花效果:

国庆烟花源码如下:

<!DOCTYPE HTML>
<html>
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>国庆烟花气氛</title><style>body {display: flex;height: 100vh; /* 页面高度 */justify-content: center; /* 水平居中 */align-items: center; /* 垂直居中 */margin: 0; /* 去掉默认边距 */position: relative;overflow: hidden;background-color: #000; /* 背景设为黑色,模拟夜空 */}.flag {width: 300px;height: 200px;background-color: red;position: relative;z-index: 1;}.star {margin: 0 0;position: absolute;display: block;width: 0;height: 0;border-right: 100px solid transparent;border-bottom: 70px solid yellow;border-left: 100px solid transparent;transform: rotate(35deg);left: 20px;}.star:before {border-bottom: 80px solid yellow;border-left: 30px solid transparent;border-right: 30px solid transparent;position: absolute;height: 0;width: 0;top: -45px;left: -65px;display: block;content: '';transform: rotate(-35deg);}.star:after {content: '';margin: 0;position: absolute;display: block;width: 0;height: 0;border-right: 100px solid transparent;border-bottom: 70px solid yellow;border-left: 100px solid transparent;transform: rotate(-70deg);left: -107px;top: 5px;}.big {transform: scale(.3) rotate(35deg);top: 10px;left: -50px;z-index: 3;}.little1 {position: absolute;transform: scale(.1) rotate(-60deg);top: -15px;left: 5px;}.little2 {position: absolute;transform: scale(.1) rotate(-45deg);top: 5px;left: 30px;}.little3 {position: absolute;transform: scale(.1) rotate(35deg);top: 33px;left: 30px;}.little4 {position: absolute;transform: scale(.1) rotate(60deg);top: 50px;left: 5px;}canvas {position: absolute;top: 0;left: 0;width: 100%;height: 100%;pointer-events: none; /* 使canvas不会阻止点击事件 */}</style>
</head>
<body><canvas id="fireworks"></canvas><div class="flag"><div class="star big"></div><div class="star little1"></div><div class="star little2"></div><div class="star little3"></div><div class="star little4"></div></div><script>const canvas = document.getElementById('fireworks');const ctx = canvas.getContext('2d');canvas.width = window.innerWidth;canvas.height = window.innerHeight;function randomColor() {return `hsl(${Math.random() * 360}, 100%, 50%)`;}function Firework(x, y) {this.x = x;this.y = y;this.size = Math.random() * 10 + 5;this.speed = Math.random() * 6 + 2;this.angle = Math.random() * Math.PI * 2;this.color = randomColor();this.exploded = false;this.particles = [];this.update = function () {if (!this.exploded) {this.y -= this.speed;// 限制烟花的最大高度if (this.y < canvas.height * 0.2) { // 高度限制this.exploded = true;this.createParticles();}if (this.size > 0) {this.size -= 0.1;} else {this.exploded = true;this.createParticles();}} else {this.particles.forEach(p => p.update());}};this.createParticles = function () {const particleCount = Math.random() * 100 + 50;for (let i = 0; i < particleCount; i++) {this.particles.push(new Particle(this.x, this.y, this.color));}};this.draw = function () {if (!this.exploded) {if (this.size > 0) { // 仅在大小为正时绘制。ctx.fillStyle = this.color;ctx.beginPath();ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);ctx.fill();}} else {this.particles.forEach(p => p.draw());}};}function Particle(x, y, color) {this.x = x;this.y = y;// 将颜色分解为RGB,以便后续使用this.color = color.match(/\d+/g).map(Number);this.size = Math.random() * 3 + 2;this.speed = Math.random() * 3 + 1;this.angle = Math.random() * Math.PI * 2;this.alpha = 1;this.update = function () {this.x += Math.cos(this.angle) * this.speed;this.y += Math.sin(this.angle) * this.speed;this.alpha -= 0.02;};this.draw = function () {ctx.fillStyle = `rgba(${this.color.join(",")}, ${this.alpha})`;if (this.alpha > 0) { // 仅当透明度为正时绘制。ctx.beginPath();ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);ctx.fill();}};}const fireworks = [];function createFirework() {const firework = new Firework(Math.random() * canvas.width, canvas.height);fireworks.push(firework);}function animate() {ctx.clearRect(0, 0, canvas.width, canvas.height);fireworks.forEach((firework, index) => {firework.update();firework.draw();if (firework.exploded && firework.particles.length === 0) {fireworks.splice(index, 1);}});requestAnimationFrame(animate);}for (let i = 0; i < 5; i++) {createFirework();}animate();setInterval(createFirework, 1000);</script>
</body>
</html>


http://www.ppmy.cn/server/128594.html

相关文章

十大时间序列预测模型

目录 1. 自回归模型 原理 核心公式 推导过程: 完整案例 2. 移动平均模型 原理 核心公式 推导过程: 完整案例 3. 自回归移动平均模型 原理 核心公式 推导过程: 完整案例 4. 自回归积分移动平均模型 原理 核心公式 推导过程 完整案例 5. 季节性自回归积分…

Koa学习

Koa 安装与配置 1. 初始化项目 在终端中执行以下命令&#xff1a; # 创建项目文件夹 mkdir koa cd koa# 初始化并安装依赖 npm init -y npm install koa npm install nodemon --save-dev2. 修改 package.json 在 package.json 文件中进行如下修改&#xff1a; {"type…

STL的位图:bitset

引言 在C标准模板库&#xff08;STL&#xff09;中&#xff0c;bitset是一种用于表示固定大小序列的位集合的容器。每个位&#xff08;bit&#xff09;可以被独立地设置或清除&#xff0c;即它可以单独地表示0或1。bitset在处理二进制数据时非常有用&#xff0c;尤其是在需要节…

Docker 实践与应用举例

一、容器化Web应用&#xff1a; 创建一个Docker容器来运行一个简单的Web应用&#xff0c;例如一个基于Node.js的Express应用。首先&#xff0c;编写Dockerfile来定义容器的构建过程&#xff0c;然后使用Docker命令来构建和运行容器。 使用Docker Compose来定义和管理多个容器组…

使用Three.js库创建的简单WebGL应用程序,主要用于展示具有不同透明度和缩放比例的圆环列

上述HTML文档是一个使用Three.js库创建的简单WebGL应用程序&#xff0c;主要用于展示具有不同透明度和缩放比例的圆环列。以下是代码的详细解释&#xff1a; HTML结构: 文档类型声明为HTML5。<html>标签设置了语言属性为英语&#xff08;lang"en"&#xff09;…

告别音乐小白!字节跳动AI音乐创作工具,让你一键变作曲家!

还在羡慕别人能创作动听的音乐&#xff1f;五音不全的你&#xff0c;也梦想着谱写属于自己的乐章&#xff1f;现在&#xff0c;机会来了&#xff01;字节跳动推出了一款AI音乐创作工具——抖音推出的海绵音乐&#xff0c;它能让你轻松一键创作音乐&#xff0c;即使是“音乐小白…

Spring MVC 常用注解

目录 基础概念 常用注解介绍 基础概念 1、MVC &#xff1a;代表一种软件架构设计思想&#xff0c;通俗的理解&#xff1a;客户端发送请求到后台服务器的Controller(C)&#xff0c;控制器调用Model(M)来处理业务逻辑&#xff0c;处理完成后&#xff0c;返回处理后的数据到Vie…

用户在网页上输入一个网址,它整个页面响应的流程是什么?

目录 一、流程的大致过程 二、流程的详细分析 1. 浏览器先分析超链接中的URL 2. DNS解析 3. 建立TCP连接 建立连接&#xff08;三次握手&#xff09; HTTP中的请求报文 4. 浏览器发送HTTP请求 5. 服务器处理请求并发送响应 HTTP的响应报文 6. 浏览器接收响应 7. 渲…