【02】v1.0.1更新增加倒计时完成后的放烟花页面-优化播放器-优化结构目录-蛇年新年快乐倒计时领取礼物放烟花html代码优雅草科技央千澈写采用html5+div+CSS+JavaScript-优雅草卓伊凡-做一条关于新年的代码分享给你们-为了C站的分拼一下子

简介: 【02】v1.0.1更新增加倒计时完成后的放烟花页面-优化播放器-优化结构目录-蛇年新年快乐倒计时领取礼物放烟花html代码优雅草科技央千澈写采用html5+div+CSS+JavaScript-优雅草卓伊凡-做一条关于新年的代码分享给你们-为了C站的分拼一下子

【02】v1.0.1更新增加倒计时完成后的放烟花页面-优化播放器-优化结构目录-蛇年新年快乐倒计时领取礼物放烟花html代码优雅草科技央千澈写采用html5+div+CSS+JavaScript-优雅草卓伊凡-做一条关于新年的代码分享给你们-为了C站的分拼一下子

开发背景

由于看到C站有个任务是上传新年主题相关的代码可以+6分,为了这6分必须拼一下子,要知道C站挣6分是有多么难的,优雅草央千澈是要冲刺全国排名的人那必须去争取一下,ok我们废话不多说开始实战吧,本次开发技术栈采用html5+div+CSS+JavaScript,用html给写一个新年放烟花并且领取一个随机新年礼物的小代码供大家送给自己心上人礼物-为了完成C站的新年主题任务-优雅草央千澈-做一条关于新年的代码分享给你们,章节共计5篇。

本文还有个事情声明下,优雅草央千澈还是改名为优雅草卓伊凡,本身自己的笔名是卓伊凡,但是酷爱霹雳侠影中的角色央千澈,因此之前一直以央千澈为名字,但是随着目前人气的升高,不免这样会影响到偶像这个名字重名,让很多道友不小心搜到我,这样不太好,因此后续所有的文章均改名为卓伊凡。

章节

【02】v1.0.1更新增加倒计时完成后的放烟花页面-优化播放器-优化结构目录

效果实时演示地址

https://happynewyear.youyacao.com/

gitee开源地址

https://gitee.com/youyacao/happynewyear

实战开发

由于认为播放器显示的内容不够多,加上播放器不够好看,因此我们优化一下 弄个好看的播放器代码,

不过== 因为卓伊凡最近才做了音乐并且提交了网易云,因此想了下直接调用网易云的音乐吧,加上卓伊凡自己的音乐放在背景也没有什么版权风险。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>网易云音乐播放器</title>
</head>
<body>
  <h1>网易云音乐播放器</h1>
  <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width="100%" height="86" src="https://music.163.com/outchain/player?type=2&id=27571483&auto=1&height=66"></iframe>
</body>
</html>

在网易云音乐播放器的外链中,id 是用来标识你想要播放的具体音乐、专辑、歌单等资源的唯一标识符。不同类型的资源有不同的 type 参数和值。以下是一些常见的资源类型及其 type id 参数的说明:

  • 单曲 (type=2):id 对应的是单曲的 ID。
  • 歌单 (type=0):id 对应的是歌单的 ID。
  • 专辑 (type=1):id 对应的是专辑的 ID。
  • 艺人 (type=4):id 对应的是艺人的 ID。

在你提供的代码示例中,id=27571483 对应的是某个特定的单曲。如果你想更改播放器中的音乐,只需要替换 id 的值为你想要播放的音乐的 ID 即可。

拿卓伊凡的例子吧,选择type=1 用专辑id,卓伊凡最新专辑——涅槃,

id 应该就是这个了 albumId=260180233

那么最终代码为:

好看多了,并且也能自动播放,挺好!另外发现个问题,背景图就一张显得非常单调,因此我们再追加2张图,关于新年的。

用MJ再做了两张图,看上去非常的不错,接下来我们要写在背景中,并且加入渐入渐出的切换变化效果。

为了实现背景图片的切换,可以使用JavaScript来定期更换背景图片。以下是具体的修改步骤:

定义背景图片数组:在JavaScript中定义一个包含所有背景图片路径的数组。
设置定时器:使用setInterval函数定期更换背景图片。
更新背景图片:编写一个函数来更新body的背景图片。
增加以下代码

// 背景图片数组
        const backgroundImages = [
            'assets/img/bg.png',
            'assets/img/bg2.jpg',
            'assets/img/bg3.jpg'
        ];
        let currentBackgroundIndex = 0;
        // 更新背景图片的函数
        function updateBackground() {
            document.body.style.backgroundImage = `url('${backgroundImages[currentBackgroundIndex]}')`;
            currentBackgroundIndex = (currentBackgroundIndex + 1) % backgroundImages.length;
        }
        // 每5秒更换一次背景图片
        setInterval(updateBackground, 5000);
        // 初始设置背景图片
        updateBackground();

搞定,看起来又好了很多,不过现在结构有点乱,我们要做两件事情,把样式文件css单独放,把JavaScript 单独放,直接嵌入页面是不合理的。

单独建立zhuoivan.css 和zhuoivan.js

<link rel="stylesheet" href="assets/css/zhuoivan.css?v=1.0.0">

放在head标签中,对应把css文件粘贴进去

放在body标签中,对应吧js内容粘贴进文件,并且移除index里面的

现在再来看:

<!--
 * @Author: 卓伊凡
 * @LastEditors: 卓伊凡
 * @email: 422108995@qq.com
 * @github: https://github.com/youyacao
 * @gitee: https://gitee.com/youyacao/
 * @Date: 2025-01-18 13:35:41
 * @LastEditTime: 2025-01-20 10:31:53
 * @motto: Still water runs deep
 * @Description: 优雅草科技卓伊凡-优雅草科技主程-兼技术总监-优雅草科技欢迎合作共赢,优雅草科技官网www.youyacao.com,感谢合作与支持,请仔细阅读优雅草科技的开源lisence文件,您可以百分百100%使用优雅草的开源产品,但是需要遵守相关规则,并且需要申明是使用了优雅草科技的产品
 * @FilePath: \happynewyear\index.html
-->
<!--
 * @Author: 卓伊凡
 * @LastEditors: 卓伊凡
 * @email: 422108995@qq.com
 * @github: https://github.com/youyacao
 * @gitee: https://gitee.com/youyacao/
 * @Date: 2025-01-18 13:35:41
 * @LastEditTime: 2025-01-20 10:31:37
 * @motto: Still water runs deep
 * @Description: 优雅草科技卓伊凡-优雅草科技主程-兼技术总监-优雅草科技欢迎合作共赢,优雅草科技官网www.youyacao.com,感谢合作与支持,请仔细阅读优雅草科技的开源lisence文件,您可以百分百100%使用优雅草的开源产品,但是需要遵守相关规则,并且需要申明是使用了优雅草科技的产品
 * @FilePath: \happynewyear\index.html
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>2025年蛇年-新年倒计时-优雅草央千澈</title>
    <link rel="stylesheet" href="assets/css/zhuoivan.css?v=1.0.0">
</head>
<body>
    <script src="assets/js/zhuoivan.js?v=1.0.0"></script>
    <div id="countdown-container">
        <div id="countdown-title">2025年蛇年除夕夜倒计时·优雅草科技-卓伊凡</div>
        <div id="countdown"></div>
        <div id="audio-player">
            <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width="100%" height="86" src="https://music.163.com/outchain/player?type=1&id=260180233&auto=1&height=66"></iframe>
        </div>
    </div>
    <div class="firework firework-left"></div>
    <div class="firework firework-right"></div>
</body>
</html>

非常的简介明了,好了 我们现在需要增加一个放烟花页面,就叫celebrate.html吧

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>2025年蛇年-新年烟花秀</title>
    <style>
        body {
            background-color: black;
            margin: 0;
            overflow: hidden;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        canvas {
            position: absolute;
            top: 0;
            left: 0;
        }
    </style>
</head>
<body>
    <canvas id="fireworks"></canvas>
    <script>
        const canvas = document.getElementById('fireworks');
        const ctx = canvas.getContext('2d');
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
        class Firework {
            constructor(x, y) {
                this.x = x;
                this.y = y;
                this.size = Math.random() * 4 + 1;
                this.speed = Math.random() * 4 + 2;
                this.color = `hsl(${Math.random() * 360}, 100%, 50%)`;
                this.exploded = false;
                this.particles = [];
            }
            update() {
                if (!this.exploded) {
                    this.y -= this.speed;
                    if (this.y < canvas.height / 2) {
                        this.explode();
                    }
                } else {
                    for (let i = 0; i < this.particles.length; i++) {
                        this.particles[i].update();
                        if (this.particles[i].alpha <= 0) {
                            this.particles.splice(i, 1);
                            i--;
                        }
                    }
                }
            }
            draw() {
                if (!this.exploded) {
                    ctx.beginPath();
                    ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
                    ctx.fillStyle = this.color;
                    ctx.fill();
                } else {
                    for (let particle of this.particles) {
                        particle.draw();
                    }
                }
            }
            explode() {
                this.exploded = true;
                for (let i = 0; i < 100; i++) {
                    this.particles.push(new Particle(this.x, this.y, this.color));
                }
            }
        }
        class Particle {
            constructor(x, y, color) {
                this.x = x;
                this.y = y;
                this.size = Math.random() * 2 + 1;
                this.speed = {
                    x: (Math.random() - 0.5) * 5,
                    y: (Math.random() - 0.5) * 5
                };
                this.gravity = 0.05;
                this.alpha = 1;
                this.color = color;
            }
            update() {
                this.x += this.speed.x;
                this.y += this.speed.y;
                this.speed.y += this.gravity;
                this.alpha -= 0.01;
            }
            draw() {
                ctx.beginPath();
                ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
                ctx.fillStyle = `rgba(${this.color}, ${this.alpha})`;
                ctx.fill();
            }
        }
        let fireworks = [];
        function createFirework() {
            const x = Math.random() * canvas.width;
            const y = canvas.height;
            fireworks.push(new Firework(x, y));
        }
        function animate() {
            ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
            ctx.fillRect(0, 0, canvas.width, canvas.height);
            for (let i = 0; i < fireworks.length; i++) {
                fireworks[i].update();
                fireworks[i].draw();
                if (fireworks[i].exploded && fireworks[i].particles.length === 0) {
                    fireworks.splice(i, 1);
                    i--;
                }
            }
            requestAnimationFrame(animate);
        }
        setInterval(createFirework, 1000);
        animate();
    </script>
</body>
</html>

以上代码:

  1. HTML结构:包含一个<canvas>元素,用于绘制烟花效果。
  2. CSS样式:设置背景为黑色,并隐藏滚动条。
  3. JavaScript代码
  • Firework类:表示一个烟花,包含位置、大小、速度、颜色等属性,以及更新和绘制方法。
  • Particle类:表示烟花爆炸后的粒子,包含位置、大小、速度、重力、透明度等属性,以及更新和绘制方法。
  • createFirework函数:创建一个新的烟花并添加到fireworks数组中。
  • animate函数:清除画布,更新和绘制所有烟花及其粒子,并使用requestAnimationFrame循环动画。
  • setInterval:每秒创建一个新的烟花。

稍微在调整下,让烟花可以升空到最顶部,让烟花爆炸变成随机事件

class Firework {
            constructor(x, y) {
                this.x = x;
                this.y = y;
                this.size = Math.random() * 4 + 1;
                this.speed = Math.random() * 4 + 2;
                this.color = `hsl(${Math.random() * 360}, 100%, 50%)`;
                this.exploded = false;
                this.particles = [];
                this.targetHeight = Math.random() * canvas.height * 0.5; // 随机爆炸高度
            }

随机爆炸高度:

在Firework类的构造函数中添加了一个targetHeight属性,该属性是一个随机值,范围在0到画布高度的一半之间。
在update方法中,检查烟花的位置是否小于targetHeight,如果是,则调用explode方法。

烟花上升到最顶部:

通过设置targetHeight为随机值,烟花可以在不同的高度爆炸,但仍然会升空到画布的最顶部。

浏览器看了下效果,还行,就是可以调整下 速度 还有大小,完了下一步 再配上烟花爆竹声音就很不错了,对了,这个页面不能不加祝福词呀。

新年伊始,愿你像小蛇般灵动,在生活的舞台上轻盈起舞,收获满满的惊喜与欢乐,这句祝福词不错。

为了在页面加载后显示带有渐变效果的祝福词文字,我们可以使用CSS和JavaScript来实现。具体步骤如下:

  1. 添加HTML元素:在页面中添加一个用于显示祝福词的<div>元素。
  2. 添加CSS样式:定义祝福词的样式,包括渐变效果。
  3. 使用JavaScript:在页面加载后,通过JavaScript控制祝福词的渐变效果。

以下是具体的实现步骤:
1. 添加HTML元素

<body>中添加一个<div>元素来显示祝福词。

完整代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>2025年蛇年-新年烟花秀-优雅草卓伊凡</title>
    <style>
        body {
            background-color: black;
            margin: 0;
            overflow: hidden;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        canvas {
            position: absolute;
            top: 0;
            left: 0;
        }
        #message {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            font-size: 24px;
            color: white;
            opacity: 0;
            text-align: center;
            transition: opacity 3s ease-in-out;
        }
    </style>
</head>
<body>
    <canvas id="fireworks"></canvas>
    <div id="message">新年伊始,愿你像小蛇般灵动,在生活的舞台上轻盈起舞,收获满满的惊喜与欢乐</div>
    <script>
        const canvas = document.getElementById('fireworks');
        const ctx = canvas.getContext('2d');
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
        class Firework {
            constructor(x, y) {
                this.x = x;
                this.y = y;
                this.size = Math.random() * 4 + 1;
                this.speed = Math.random() * 4 + 2;
                this.color = `hsl(${Math.random() * 360}, 100%, 50%)`;
                this.exploded = false;
                this.particles = [];
                this.targetHeight = Math.random() * canvas.height * 0.5; // 随机爆炸高度
            }
            update() {
                if (!this.exploded) {
                    this.y -= this.speed;
                    if (this.y < canvas.height / 2) {
                        this.explode();
                    }
                } else {
                    for (let i = 0; i < this.particles.length; i++) {
                        this.particles[i].update();
                        if (this.particles[i].alpha <= 0) {
                            this.particles.splice(i, 1);
                            i--;
                        }
                    }
                }
            }
            draw() {
                if (!this.exploded) {
                    ctx.beginPath();
                    ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
                    ctx.fillStyle = this.color;
                    ctx.fill();
                } else {
                    for (let particle of this.particles) {
                        particle.draw();
                    }
                }
            }
            explode() {
                this.exploded = true;
                for (let i = 0; i < 100; i++) {
                    this.particles.push(new Particle(this.x, this.y, this.color));
                }
            }
        }
        class Particle {
            constructor(x, y, color) {
                this.x = x;
                this.y = y;
                this.size = Math.random() * 2 + 1;
                this.speed = {
                    x: (Math.random() - 0.5) * 5,
                    y: (Math.random() - 0.5) * 5
                };
                this.gravity = 0.05;
                this.alpha = 1;
                this.color = color;
            }
            update() {
                this.x += this.speed.x;
                this.y += this.speed.y;
                this.speed.y += this.gravity;
                this.alpha -= 0.01;
            }
            draw() {
                ctx.beginPath();
                ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
                ctx.fillStyle = `rgba(${this.color}, ${this.alpha})`;
                ctx.fill();
            }
        }
        let fireworks = [];
        function createFirework() {
            const x = Math.random() * canvas.width;
            const y = canvas.height;
            fireworks.push(new Firework(x, y));
        }
        function animate() {
            ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
            ctx.fillRect(0, 0, canvas.width, canvas.height);
            for (let i = 0; i < fireworks.length; i++) {
                fireworks[i].update();
                fireworks[i].draw();
                if (fireworks[i].exploded && fireworks[i].particles.length === 0) {
                    fireworks.splice(i, 1);
                    i--;
                }
            }
            requestAnimationFrame(animate);
        }
        setInterval(createFirework, 1000);
        animate();
         // 渐变效果
         window.onload = function() {
            const message = document.getElementById('message');
            message.style.opacity = 1;
        };
    </script>
</body>
</html>

ok 新年主题代码告一段落,v1.0.1更新

目录
相关文章
|
4月前
|
JavaScript 前端开发 开发者
Vue 动态添加 HTML 元素组件封装使用方法及长尾关键词优化指南
本文详细介绍了Vue中动态添加HTML元素的使用方法与组件封装技巧。内容涵盖条件渲染(v-if/v-show)、列表渲染(v-for)、动态组件(:is)、手动操作DOM及动态创建组件实例等核心方法。同时,通过动态表单、弹窗组件和动态加载组件的封装示例,展示如何提升代码复用性和可维护性。最后,总结性能优化策略与注意事项,如批量更新DOM、懒加载大型组件及避免直接操作DOM等,帮助开发者在实际项目中灵活应用Vue动态元素管理功能。
102 15
|
3月前
|
存储 前端开发 安全
病历单生成器在线制作,病历单生成器app,HTML+CSS+JS恶搞工具
本项目为医疗病历模拟生成器,旨在为医学教学和软件开发测试提供数据支持,严格遵守《医疗机构病历管理规定》。
|
3月前
|
存储 前端开发 JavaScript
仿真银行app下载安装, 银行卡虚拟余额制作app,用html+css+js实现逼真娱乐工具
这是一个简单的银行账户模拟器项目,用于学习前端开发基础。用户可进行存款、取款操作,所有数据存储于浏览器内存中
|
4月前
|
JavaScript 前端开发 开发者
Vue 动态添加 HTML 元素组件封装使用方法及长尾关键词优化指南
本文详细介绍了Vue中动态添加HTML元素的多种方法与组件封装技巧,涵盖条件渲染(v-if/v-show)、列表渲染(v-for)、动态组件(:is)、手动DOM操作及动态创建组件实例等内容。同时提供了性能优化建议,如批量更新DOM、使用v-show代替v-if以及懒加载大型组件等。通过合理封装组件,可提高代码复用性和维护性。文中还附有具体示例代码,帮助开发者更好地理解和应用相关技术。适用于前端开发人员学习和实践Vue动态元素处理与组件设计。
115 19
|
8月前
|
人工智能 程序员 UED
【01】完成新年倒计时页面-蛇年新年快乐倒计时领取礼物放烟花html代码优雅草科技央千澈写采用html5+div+CSS+JavaScript-优雅草卓伊凡-做一条关于新年的代码分享给你们-为了C站的分拼一下子
【01】完成新年倒计时页面-蛇年新年快乐倒计时领取礼物放烟花html代码优雅草科技央千澈写采用html5+div+CSS+JavaScript-优雅草卓伊凡-做一条关于新年的代码分享给你们-为了C站的分拼一下子
328 21
【01】完成新年倒计时页面-蛇年新年快乐倒计时领取礼物放烟花html代码优雅草科技央千澈写采用html5+div+CSS+JavaScript-优雅草卓伊凡-做一条关于新年的代码分享给你们-为了C站的分拼一下子
|
7月前
|
前端开发
【2025优雅草开源计划进行中01】-针对web前端开发初学者使用-优雅草科技官网-纯静态页面html+css+JavaScript可直接下载使用-开源-首页为优雅草吴银满工程师原创-优雅草卓伊凡发布
【2025优雅草开源计划进行中01】-针对web前端开发初学者使用-优雅草科技官网-纯静态页面html+css+JavaScript可直接下载使用-开源-首页为优雅草吴银满工程师原创-优雅草卓伊凡发布
188 1
【2025优雅草开源计划进行中01】-针对web前端开发初学者使用-优雅草科技官网-纯静态页面html+css+JavaScript可直接下载使用-开源-首页为优雅草吴银满工程师原创-优雅草卓伊凡发布
|
8月前
css3实现3D数字时钟滚动特效代码
css3实现3D数字时钟滚动特效代码
314 18
|
前端开发 JavaScript UED
【专栏:HTML与CSS移动端开发篇】移动端触摸事件与手势识别
【4月更文挑战第30天】本文探讨了移动端触摸事件和手势识别在网页开发中的重要性。介绍了基础触摸事件如`touchstart`, `touchmove`, `touchend`, `touchcancel`及相关属性。文章列举了处理触摸事件的方法,包括单点触摸、多点触摸、滑动、长按、捏合缩放、旋转检测和事件代理。建议使用第三方库如Hammer.js简化手势处理,并分享了最佳实践,如避免意外触摸、提供视觉反馈、考虑性能和跨设备测试。理解并有效利用这些技术能提升用户交互体验。
478 7
|
缓存 前端开发 JavaScript
【专栏:HTML与CSS移动端开发篇】移动端网页性能优化策略
【4月更文挑战第30天】本文探讨了移动端网页性能优化的重要性,并提出了优化策略。HTML方面,建议精简结构、使用语义化标签、异步加载脚本和压缩文件;CSS优化包括精简样式、使用CSS3动画、媒体查询和压缩文件。其他策略涉及图片和字体压缩、缓存利用、数据压缩、减少HTTP请求及根据网络状态调整加载。综合运用这些策略能提升网页性能和用户体验。
262 6
|
编解码 移动开发 前端开发
【专栏:HTML与CSS移动端开发篇】使用Viewport Meta标签优化移动端显示
【4月更文挑战第30天】本文介绍了HTML的Viewport Meta标签在移动端网页优化中的作用。Viewport Meta标签定义了视口属性,如宽度、高度、初始缩放等,解决移动设备因屏幕尺寸差异导致的显示问题。主要属性包括width(常用device-width)、initial-scale、maximum-scale、minimum-scale和user-scalable。
426 4