vue.js+vite搭建一个简单的新春祈福活动网站

vue.js+vite搭建一个简单的新春祈福活动网站!使用canvas技术,绘制视觉特效。


功能有:燃放烟花,和撞钟祈福。祈福撞钟我设计了是按钮事件,播放一个mp4动画,配上播放一段撞钟的生效文件mp3.


<template><NavBar /><div class="bell-container"><!-- 撞钟按钮 --><button @click="ringBell" class="bell-button" :disabled="isButtonDisabled">撞钟</button><!-- 视频元素:页面加载时显示 --><video ref="bellVideo" style="width: 300px; height: 300px;" preload="auto" autoplay><source :src="bellVideo" type="video/mp4" />您的浏览器不支持视频播放。</video><!-- 显示消息 --><p v-if="message" class="message">{{ message }}</p><!-- 欢迎标语 --><div class="welcome-banner"><p>欢迎参与撞钟祈福,愿您好运常在,新春快乐!</p></div></div>
</template><script>
import NavBar from '@/components/NavBar.vue';
import bellAudio from '@/assets/audio/zhong.mp3';  // MP3 格式音频
import bellVideo from '@/assets/mp4/zhong.mp4';  // MP4 格式视频
import { Howl } from 'howler';export default {data() {return {message: "",bellSound: null, // 用来保存 Howler 实例bellVideo, // 保存视频路径isButtonDisabled: false, // 控制按钮是否禁用};},components: {NavBar},mounted() {// 初始化音效(MP3)this.bellSound = new Howl({src: [bellAudio],  // 使用 import 引入的音频路径volume: 0.8,onplayerror: () => {console.error('播放音频失败');}});},methods: {// 播放撞钟音效和视频的方法ringBell() {// 播放音效(MP3)this.bellSound.play();// 获取视频元素并播放const videoElement = this.$refs.bellVideo;if (videoElement) {// 视频播放videoElement.play().catch(error => {console.error('播放视频失败:', error);});} else {console.error('未找到视频元素');}// 显示消息this.message = "恭喜你,撞钟祈福成功!";// 5秒后清除消息setTimeout(() => {this.message = "";}, 5000);// 禁用按钮,6秒后再启用this.isButtonDisabled = true;setTimeout(() => {this.isButtonDisabled = false;}, 6000); // 6秒后启用按钮}}
};
</script><style scoped>
/* 全局布局:使用 Flexbox 实现居中 */
.bell-container {display: flex;flex-direction: column; /* 垂直排列 */align-items: center;    /* 水平居中 */justify-content: center; /* 垂直居中 */text-align: center;height: 85vh; /* 占满屏幕高度 */background-color: #F9E4B7; /* 温暖的浅黄色 */padding: 20px;box-sizing: border-box;
}.welcome-banner {margin-top: 30px;background-color: #FFDD8C; /* 亮黄色背景 */padding: 36px 30px;border-radius: 5px;font-size: 18px;font-weight: bold;color: #E23E34; /* 喜庆的红色 */animation: fadeIn 3s ease-in-out;
}/* 撞钟按钮样式 */
.bell-button {padding: 12px;font-size: 14px;background-color: #f0c030; /* 喜庆的黄色 */color: white;border: none;cursor: pointer;margin-bottom: 12px;border-radius: 10px;transition: background-color 0.3s ease;
}/* 禁用按钮样式 */
.bell-button:disabled {background-color: #cccccc;cursor: not-allowed;
}/* 按钮悬停时的效果 */
.bell-button:hover {background-color: #e0b030;
}/* 播放消息 */
.message {margin-top: 20px;font-size: 20px;font-weight: bold;color: green;
}/* 令文本欢迎标语逐渐显示 */
@keyframes fadeIn {from {opacity: 0;}to {opacity: 1;}
}video {margin-top: 20px;border-radius: 10px;box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
</style>

2:下面是燃放烟花的组件内容。

<template><NavBar /><div class="fireworks-container"><div v-if="showText" :style="{ color: popupTextColor }" class="popup-text">{{ popupText }}</div> <!-- 弹屏显示文本 --><button @click="launchFireworks" class="fireworks-button">燃放烟花</button><div class="image-container"><img src="@/assets/images/yanhua.png" alt="烟花图标" class="yanhua-image" /><br/><span style="color: red;">多次燃放,看见不同祝福哦</span></div><canvas ref="fireworksCanvas" class="canvas-container"></canvas></div></template><script>import yanhua from '@/assets/audio/yanhua.mp3';  // MP3 格式音频import { Howl } from 'howler';import NavBar from '@/components/NavBar.vue';export default {data() {return {fireworks: [], // 存储所有的烟花粒子animationFrameId: null, // 用于停止动画fireworksAudio: null, // 用于保存音频对象showText: false, // 控制是否显示弹屏文本popupTextColor: '', // 弹屏文本的颜色popupText: '', // 当前显示的贺词// 新春贺词数组greetings: ["新春快乐,万事如意!","心想事成,春风得意!","财源广进,生意兴隆!","吉祥如意,福星高照!","花开富贵,幸福安康!","恭喜发财,步步高升!","大吉大利,心想事成!","事事顺心,岁岁平安!",],};},components: {NavBar,},mounted() {// 获取 canvas 元素this.canvas = this.$refs.fireworksCanvas;this.ctx = this.canvas.getContext("2d");// 设置 canvas 尺寸为视口宽度和高度this.canvas.width = window.innerWidth;this.canvas.height = window.innerHeight;// 初始化音效(MP3)this.fireworksAudio = new Howl({src: [yanhua],  // 使用 import 引入的音频路径volume: 0.8,onplayerror: () => {console.error('播放烟花音频失败');},});},methods: {// 启动烟花效果launchFireworks() {// 随机生成颜色const randomColor = `hsl(${Math.random() * 360}, 100%, 50%)`;this.popupTextColor = randomColor; // 设置弹屏文本的颜色// 随机选择一条新春贺词const randomGreeting = this.greetings[Math.floor(Math.random() * this.greetings.length)];console.log('随机贺词:', randomGreeting); // 打印随机选择的贺词this.popupText = randomGreeting; // 设置显示的贺词// 显示弹屏文本this.showText = true;// 设置文本显示的持续时间 (5秒)setTimeout(() => {this.showText = false;}, 5000);// 播放音效并触发烟花效果if (this.fireworksAudio) {this.fireworksAudio.play();this.fireworks = []; // 清空当前的烟花this.createFirework(randomColor); // 创建一个新的烟花并传递颜色this.animateFireworks(); // 开始绘制烟花动画} else {console.error("音频未能正确初始化!");}},// 创建一个新的烟花爆炸createFirework(color) {const firework = {x: Math.random() * this.canvas.width,y: Math.random() * (this.canvas.height / 2),color: color, // 使用传递的颜色particles: [],};for (let i = 0; i < 200; i++) {const angle = Math.random() * 2 * Math.PI;const speed = Math.random() * 5 + 2;firework.particles.push({x: firework.x,y: firework.y,speedX: Math.cos(angle) * speed,speedY: Math.sin(angle) * speed,life: 1,color: firework.color, // 设置粒子的颜色});}this.fireworks.push(firework);},// 动画渲染烟花效果animateFireworks() {this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);for (let i = 0; i < this.fireworks.length; i++) {const firework = this.fireworks[i];for (let j = 0; j < firework.particles.length; j++) {const particle = firework.particles[j];particle.x += particle.speedX;particle.y += particle.speedY;particle.speedY += 0.1;this.ctx.beginPath();this.ctx.arc(particle.x, particle.y, 4, 0, Math.PI * 2);this.ctx.fillStyle = particle.color;this.ctx.fill();particle.life -= 0.01;}firework.particles = firework.particles.filter(p => p.life > 0);}if (this.fireworks.some(f => f.particles.length > 0)) {this.animationFrameId = requestAnimationFrame(this.animateFireworks);} else {cancelAnimationFrame(this.animationFrameId);}},},};</script><style scoped>.fireworks-container {text-align: center;margin-top: 5px;background-color: #000;color: white;height: 100vh;display: flex;flex-direction: column;justify-content: center;align-items: center;overflow: hidden;}.fireworks-button {background-color: #e74c3c;color: white;padding: 10px;font-size: 14px;cursor: pointer;border-radius: 5px;border: none;margin-bottom: 20px;}.image-container {margin: 20px 0;}.yanhua-image {width: 100px;height: 100px;object-fit: cover;}.canvas-container {position: absolute;top: 0;left: 0;width: 100%;height: 100%;pointer-events: none;background-color: transparent;}/* 弹屏文本样式 */.popup-text {position: absolute;top: 35%;left: 50%;transform: translate(-50%, -50%);font-size: 36px;font-weight: bold;opacity: 1;animation: fadeOut 3s ease-out forwards; /* 动画效果 */}/* 弹屏文本消失的动画 */@keyframes fadeOut {0% {opacity: 1;}100% {opacity: 0;}}</style>

最终成品网站如图所示:


欢迎大家测试入口网站地址:http://chunjie.hotdoger.com 

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

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

相关文章

vue3Class 与 Style 绑定

绑定 HTML class 1. 绑定对象 <div :class"{ active: isActive }"></div><divclass"static":class"{ active: isActive, text-danger: hasError }" ></div> //<div class"static active"></div>…

在 Ubuntu 下通过 Docker 部署 MySQL 服务器

引言 Docker 是一个开源的容器化平台&#xff0c;允许开发者将应用及其依赖打包成一个标准化的单元。MySQL 是一个广泛使用的关系型数据库管理系统&#xff0c;因其高性能、可靠性和易用性&#xff0c;成为许多应用的首选数据库。结合 Docker 和 MySQL&#xff0c;可以轻松地创…

有机物谱图信息的速查技巧有哪些?

谱图信息是化学家解读分子世界的“语言”&#xff0c;它们在化学研究的各个领域都发挥着不可或缺的作用。它们是理解和确定分子结构的关键&#xff0c;对化学家来说极为重要&#xff0c;每一种谱学技术都提供了不同的视角来观察分子&#xff0c;从而揭示其独特的化学和物理特性…

C++指针类型的基本理论和使用方式-学习记录

一、指针简概 &#xff08;一&#xff09;指针定义 指针&#xff08;pointer&#xff09;是“指向&#xff08;point to&#xff09;”另外一种类型的复合类型。与引用类似&#xff0c;指针也实现了对其他对象的间接访问。然而指针与引用相比又有很多不同点。其一&#xff0c;…

视频转码对画质有影响吗?视频融合平台EasyCVR支持哪些转码格式?

视频转码过程是将视频文件从一种编码格式转换为另一种格式的过程&#xff0c;这一过程在现代数字媒体中扮演着至关重要的角色。众所周知&#xff0c;视频转码不仅仅是简单的格式转换&#xff0c;它涉及多个关键参数的改变&#xff0c;例如视频编码格式、比特率、分辨率以及帧率…

微信小程序防止重复点击事件

直接写在app.wpy里面&#xff0c;全局可以调用 // 防止重复点击事件preventActive(fn) {const self this;if (this.globalData.PageActive) {this.globalData.PageActive false;if (fn) fn();setTimeout(() > {self.globalData.PageActive true;}, 3000); //设置该时间内…

STM32-WWDG/IWDG看门狗

WWDG/IWDG一旦开启不能关闭&#xff0c;可通过选项字节在上电时启动硬件看门狗&#xff0c;看门狗计数只能写入不能读取。看门狗启用时&#xff0c;T6bit必须置1&#xff0c;防止立即重置。 一、原理 独立看门狗-超时复位 窗口看门狗-喂狗&#xff08;重置计数器&#xff0c;…

【计算机网络】什么是AC和AP?

在现代的无线网络中&#xff0c;AC&#xff08;Access Controller&#xff0c;接入控制器&#xff09;和AP&#xff08;Access Point&#xff0c;无线接入点&#xff09;是两个至关重要的设备&#xff0c;它们在网络的管理、连接和优化中扮演着重要角色。理解它们的功能和区别&…

C++初阶—CC++内存管理

第一章&#xff1a;C/C内存分布 int globalVar 1; static int staticGlobalVar 1; void Test() {static int staticVar 1;int localVar 1;int num1[10] { 1, 2, 3, 4 };char char2[] "abcd";const char* pChar3 "abcd";int* ptr1 (int*)malloc(si…

排序的本质、数据类型及算法选择

排序的本质、数据类型及算法选择 一、排序的本质二、排序的数据类型三、排序算法的选择依据 前两天老金写了篇 “十大排序简介”&#xff0c;有点意犹未尽&#xff0c;这一回老金想把排序连根拔起&#xff0c;从排序的本质说道说道。 一、排序的本质 从字面上理解&#xff0c…

arcgisPro加载天地图(CGCS2000)影像

1、注册天地图账号&#xff1b; 2、申请key&#xff1b; 3、添加WMTS服务器。 这里已经办好了前两步&#xff0c;下面详细介绍最后一步。 添加WMTS服务器。 在天地图网站&#xff0c;找到如下页面&#xff0c; 复制网址&#xff0c;如&#xff1a;http://t0.tianditu.gov.cn…

【测试】持续集成CI/CD

近期更新完毕&#xff0c;建议关注收藏点赞&#xff5e; 目录 概括gitJenkinspostman集成jenkins代码集成jenkins 概括 CI/CD stands for Continuous Integration and Continuous Deployment 定义 团队成果持续集成到公共平台。一天可以集成1次or多次 本地代码管理 git 远程代…

python基础和redis

1. Map函数 2. filter函数 numbers generate_numbers() filtered_numbers filter(lambda x: x % 2 0, numbers) for _ in range(5):print(next(filtered_numbers)) # 输出: 0 2 4 6 83. filter map 和 reduce 4. picking and unpicking 5. python 没有函数的重载&#xff0…

Three.js 性能优化:打造流畅高效的3D应用

文章目录 前言一、减少几何体复杂度&#xff08;Reduce Geometry Complexity&#xff09;二、合并几何体&#xff08;Merge Geometries&#xff09;三、使用缓冲区几何体&#xff08;Use BufferGeometries&#xff09;四、纹理压缩与管理&#xff08;Texture Compression and M…

人工智能及深度学习的一些题目(常错)

1、【判断题】HMM的状态序列即不能直接获得&#xff0c;也不能通过观测序列获得。 错误 HMM可以通过观测序列获得状态序列 2、【单选题】当设计一个全连接网络完成INIST字符识别实验时&#xff0c;初始网络设计为两层隐藏层&#xff0c;每层分别有874个和128个神经元 3、【单…

20250110_ PyTorch中的张量操作

文章目录 前言1、torch.cat 函数2、索引、维度扩展和张量的广播3、切片操作3.1、 encoded_first_node3.2、probs 4、长难代码分析4.1、selected4.1.1、multinomial(1)工作原理&#xff1a; 总结 前言 1、torch.cat 函数 torch.cat 函数将两个张量拼接起来&#xff0c;具体地是…

【再谈设计模式】模板方法模式 - 算法骨架的构建者

一、引言 在软件工程、软件开发过程中&#xff0c;我们经常会遇到一些算法或者业务逻辑具有固定的流程步骤&#xff0c;但其中个别步骤的实现可能会因具体情况而有所不同的情况。模板方法设计模式&#xff08;Template Method Design Pattern&#xff09;就为解决这类问题提供了…

安卓app抓包总结(精)

前言 这里简单记录一下相关抓包工具证书的安装 burp证书安装 安装证书到移动设备(安卓7以后必须上传到设备系统根证书上) 导出证书 openssl x509 -inform DER -in cacert.der -out cacert.pem 转换格式 openssl x509 -inform PEM -subject_hash_old -in cacert.pem …

【pycharm发现找不到python打包工具,且无法下载】

发现找不到python打包工具,且无法下载 解决方法&#xff1a; 第一步&#xff1a;安装distutils&#xff0c;在CMD命令行输入&#xff1a; python -m ensurepip --default-pip第二步&#xff1a;检查和安装setuptools和wheel&#xff1a; python -m pip install --upgrade …

2025年VGC大众汽车科技社招入职测评综合能力英语口语SHL历年真题汇总、考情分析

早在1978年&#xff0c;大众汽车集团就开始了与中国的联系。1984年&#xff0c;集团在华的第一家合资企业—上汽大众汽车有限公司奠基成立&#xff1b;1991年&#xff0c;一汽-大众汽车有限公司成立&#xff1b;2017年&#xff0c;大众汽车&#xff08;安徽&#xff09;有限公司…