2024年最全烟花代码,予心上人最璀璨烟花—— 附源码与成品(HTML+CSS+JS(1),关于前端程序员最近的状况

前端资料汇总

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

我一直觉得技术面试不是考试,考前背背题,发给你一张考卷,答完交卷等通知。

首先,技术面试是一个 认识自己 的过程,知道自己和外面世界的差距。

更重要的是,技术面试是一个双向了解的过程,要让对方发现你的闪光点,同时也要 试图去找到对方的闪光点,因为他以后可能就是你的同事或者领导,所以,面试官问你有什么问题的时候,不要说没有了,要去试图了解他的工作内容、了解这个团队的氛围。
找工作无非就是看三点:和什么人、做什么事、给多少钱,要给这三者在自己的心里划分一个比例。
最后,祝愿大家在这并不友好的环境下都能找到自己心仪的归宿。

var generateStars = function generateStars(f) {

for (var e = 0; e < f; e++) {

var single = document.createElement(“div”);

single.className = e % 20 == 0 ? “spark big-spark” : e % 9 == 0 ? “spark medium-spark” : “star”;

single.setAttribute(“style”, “top:” + Math.round(Math.random() * wH) + “px;left:” + Math.round(Math.random() * wW) + “px;animation-duration:” + (Math.round(Math.random() * 3000) + 3000) + “ms;animation-delay:” + Math.round(Math.random() * 3000) + “ms;”);

backgroundRendering.appendChild(single);

}

};

generateStars(getRandom(140,240));

// 全局变量 提供内容/对象存储

let fireworksCanvas = document.getElementById(“fireworks”);

let currentFireworks = document.createElement(“canvas”);

let currentObject = currentFireworks.getContext(“2d”);

let fireworksObject = fireworksCanvas.getContext(“2d”);

currentFireworks.width = fireworksCanvas.width = window.innerWidth;

currentFireworks.height = fireworksCanvas.height = window.innerHeight;

let fireworksExplosion = [];

let autoPlayFlag = false;

// 自动加载烟花动画

window.onload = function () {

drawFireworks();

lastTime = new Date();

animationEffect();

// 背景音乐

let audio = document.getElementById(‘bgm’);

document.querySelector(“body”).onclick = function () {

if (!autoPlayFlag) {

audio.play();

autoPlayFlag = true;

}

}

for (let i = 0; i <= 10; i++){

setTimeout(function () {

document.querySelector(“body > div.message”).style.opacity = i/10;

},i*60+2000)

};

for (let i = 0; i <= 10; i++){

setTimeout(function () {

document.querySelector(“body > div.message”).style.opacity = 1 - i/10;

},i*60+8000)

};

};

let lastTime;

// 烟花动画效果

function animationEffect() {

fireworksObject.save();

fireworksObject.fillStyle = “rgba(0,5,25,0.1)”;

fireworksObject.fillRect(0, 0, fireworksCanvas.width, fireworksCanvas.height);

fireworksObject.restore();

let newTime = new Date();

if (newTime - lastTime > getRandom(10,1600) + (window.innerHeight - 767) / 2) {

let random = Math.random() * 100 > 15;

let x = getRandom(0, (fireworksCanvas.width));

let y = getRandom(0,400);

if (random) {

let bigExplode = new explode(

getRandom(0, fireworksCanvas.width),

getRandom(1, 3),

“#FFF”,

{

x: x,

y: y,

}

);

fireworksExplosion.push(bigExplode);

} else {

let x = getRandom(fireworksCanvas.width/2-300, fireworksCanvas.width/2+300);

let y = getRandom(0, 350);

let bigExplode = new explode(

getRandom(0, fireworksCanvas.width),

getRandom(1, 3),

“#FFF”,

{

x: x,

y: y,

},

document.querySelectorAll(“.shape”)[

parseInt(getRandom(0, document.querySelectorAll(“.shape”).length))

]

);

fireworksExplosion.push(bigExplode);

}

lastTime = newTime;

}

sparks.foreach(function () {

this.paint();

});

fireworksExplosion.foreach(function () {

let that = this;

if (!this.dead) {

this._move();

this._drawLight();

} else {

this.explodes.foreach(function (index) {

if (!this.dead) {

this.moveTo();

} else {

if (index === that.explodes.length - 1) {

fireworksExplosion[fireworksExplosion.indexOf(that)] = null;

}

}

});

}

});

setTimeout(animationEffect, 16);

}

Array.prototype.foreach = function (callback) {

for (let i = 0; i < this.length; i++) {

if (this[i] !== null) {

callback.apply(this[i], [i]);

}

}

};

fireworksCanvas.onclick = function (evt) {

let x = evt.clientX;

let y = evt.clientY;

let explode = new explode(

getRandom(fireworksCanvas.width / 3, (fireworksCanvas.width * 2) / 3),

2,

“#FFF”,

{

x: x,

y: y,

}

);

fireworksExplosion.push(explode);

};

let explode = function (x, r, c, explodeArea, shape) {

this.explodes = [];

this.x = x;

this.y = fireworksCanvas.height + r;

this.r = r;

this.c = c;

this.shape = shape || false;

this.explodeArea = explodeArea;

this.dead = false;

this.ba = parseInt(getRandom(80, 200));

};

explode.prototype = {

_paint: function () {

fireworksObject.save();

fireworksObject.beginPath();

fireworksObject.arc(this.x, this.y, this.r, 0, 2 * Math.PI);

fireworksObject.fillStyle = this.c;

fireworksObject.fill();

fireworksObject.restore();

},

_move: function () {

let dx = this.explodeArea.x - this.x,

dy = this.explodeArea.y - this.y;

this.x = this.x + dx * 0.01;

this.y = this.y + dy * 0.01;

if (Math.abs(dx) <= this.ba && Math.abs(dy) <= this.ba) {

if (this.shape) {

this._shapeExplode();

} else {

this._explode();

}

this.dead = true;

} else {

this._paint();

}

},

_drawLight: function () {

fireworksObject.save();

fireworksObject.fillStyle = “rgba(255,228,150,0.3)”;

fireworksObject.beginPath();

fireworksObject.arc(this.x, this.y, this.r + 3 * Math.random() + 1, 0, 2 * Math.PI);

fireworksObject.fill();

fireworksObject.restore();

},

_explode: function () {

let embellishmentNum = getRandom(30, 200);

let style = getRandom(0, 10) >= 5 ? 1 : 2;

let color;

if (style === 1) {

color = {

a: parseInt(getRandom(128, 255)),

b: parseInt(getRandom(128, 255)),

c: parseInt(getRandom(128, 255)),

};

}

let fullRange = parseInt(getRandom(300, 400));

for (let i = 0; i < embellishmentNum; i++) {

if (style === 2) {

color = {

a: parseInt(getRandom(128, 255)),

b: parseInt(getRandom(128, 255)),

c: parseInt(getRandom(128, 255)),

};

}

let a = getRandom(-Math.PI, Math.PI);

let x = getRandom(0, fullRange) * Math.cos(a) + this.x;

let y = getRandom(0, fullRange) * Math.sin(a) + this.y;

let radius = getRandom(0, 2);

let embellishment = new newEmbellishment(this.x, this.y, radius, color, x, y);

this.explodes.push(embellishment);

}

},

_shapeExplode: function () {

let that = this;

putValue(currentFireworks, currentObject, this.shape, 5, function (dots) {

let dx = fireworksCanvas.width / 2 - that.x;

let dy = fireworksCanvas.height / 2 - that.y;

let color;

for (let i = 0; i < dots.length; i++) {

color = {

a: dots[i].a,

b: dots[i].b,

c: dots[i].c,

};

let x = dots[i].x;

let y = dots[i].y;

let radius = 1;

let embellishment = new newEmbellishment(that.x, that.y, radius, color, x - dx, y - dy);

that.explodes.push(embellishment);

}

});

},

};

function putValue(fireworks, context, ele, dr, callback) {

context.clearRect(0, 0, fireworksCanvas.width, fireworksCanvas.height);

let img = new Image();

let dots;

if (ele.innerHTML.indexOf(“img”) >= 0) {

img.src = ele.getElementsByTagName(“img”)[0].src;

implode(img, function () {

context.drawImage(

img,

fireworksCanvas.width / 2 - img.width / 2,

fireworksCanvas.height / 2 - img.width / 2

);

let dots = gettingData(fireworks, context, dr);

callback(dots);

});

} else {

let text = ele.innerHTML;

context.save();

let fontSize = getRandom(3,11);

context.font = fontSize + “vw 宋体 bold”;

context.textAlign = “center”;

context.textBaseline = “middle”;

context.fillStyle =

“rgba(” +

parseInt(getRandom(128, 255)) +

“,” +

parseInt(getRandom(128, 255)) +

“,” +

parseInt(getRandom(128, 255)) +

" , 1)";

context.fillText(text, fireworksCanvas.width / 2, fireworksCanvas.height / 2);

context.restore();

dots = gettingData(fireworks, context, dr);

callback(dots);

}

}

function implode(img, callback) {

if (img.complete) {

callback.call(img);

} else {

img.onload = function () {

callback.call(this);

};

}

}

function gettingData(fireworks, context, dr) {

let imgData = context.getImageData(0, 0, fireworksCanvas.width, fireworksCanvas.height);

context.clearRect(0, 0, fireworksCanvas.width, fireworksCanvas.height);

let dots = [];

for (let x = 0; x < imgData.width; x += dr) {

for (let y = 0; y < imgData.height; y += dr) {

let i = (y * imgData.width + x) * 4;

if (imgData.data[i + 3] > 128) {

let dot = {

x: x,

y: y,

a: imgData.data[i],

b: imgData.data[i + 1],

c: imgData.data[i + 2],

};

dots.push(dot);

}

}

}

return dots;

}

function getRandom(a, b) {

return Math.random() * (b - a) + a;

}

let maxRadius = 1,

sparks = [];

function drawFireworks() {

for (let i = 0; i < 100; i++) {

let spark = new newSpark();

sparks.push(spark);

spark.paint();

}

}

// 新建星火位置

let newSpark = function () {

this.x = Math.random() * fireworksCanvas.width;

this.y = Math.random() * 2 * fireworksCanvas.height - fireworksCanvas.height;

this.r = Math.random() * maxRadius;

};

newSpark.prototype = {

paint: function () {

fireworksObject.save();

fireworksObject.beginPath();

fireworksObject.arc(this.x, this.y, this.r, 0, 2 * Math.PI);

fireworksObject.fillStyle = “rgba(255,255,255,” + this.r + “)”;

fireworksObject.fill();

fireworksObject.restore();

},

};

// 烟花点缀生成

let newEmbellishment = function (centerX, centerY, radius, color, tx, ty) {

this.tx = tx;

this.ty = ty;

this.x = centerX;

this.y = centerY;

this.dead = false;

this.radius = radius;

this.color = color;

};

newEmbellishment.prototype = {

paint: function () {

fireworksObject.save();

fireworksObject.beginPath();

fireworksObject.arc(this.x, this.y, this.radius, 0, 2 * Math.PI);

fireworksObject.fillStyle =

“rgba(” + this.color.a + “,” + this.color.b + “,” + this.color.c + “,1)”;

fireworksObject.fill();

fireworksObject.restore();

},

moveTo: function () {

this.ty = this.ty + 0.3;

let dx = this.tx - this.x,

dy = this.ty - this.y;

this.x = Math.abs(dx) < 0.1 ? this.tx : this.x + dx * 0.1;

this.y = Math.abs(dy) < 0.1 ? this.ty : this.y + dy * 0.1;

if (dx === 0 && Math.abs(dy) <= 80) {

this.dead = true;

}

this.paint();

},

};

👑成品下载 👑

========================================================================

项目已经部署好了,并且代码已经上传到GitCode上了,可以直接使用和自定义

其实前端开发的知识点就那么多,面试问来问去还是那么点东西。所以面试没有其他的诀窍,只看你对这些知识点准备的充分程度。so,出去面试时先看看自己复习到了哪个阶段就好。

这里再分享一个复习的路线:(以下体系的复习资料是我从各路大佬收集整理好的)

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

《前端开发四大模块核心知识笔记》

最后,说个题外话,我在一线互联网企业工作十余年里,指导过不少同行后辈。帮助很多人得到了学习和成长。

我意识到有很多经验和知识值得分享给大家,也可以通过我们的能力和经验解答大家在IT学习中的很多困惑,所以在工作繁忙的情况下还是坚持各种整理和分享。

  • 20
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
HTMLCSS烟花代码是一种可以在网页上实现烟花效果的代码。具体实现方法如下: 1. 首先,在HTML文件中添加一个canvas标签,用于绘制烟花效果。 2. 在CSS文件中设置canvas标签的宽高等样式属性。 3. 在JS文件中编写绘制烟花效果的代码。具体实现方式如下: - 定义一个粒子对象,包括粒子的位置、速度、颜色等属性。 - 定义一个粒子数组,用于存储多个粒子对象。 - 编写一个update函数,用于更新每个粒子对象的位置、速度等属性,并将其绘制到canvas上。 - 编写一个render函数,用于不断调用update函数并清空canvas画布。 4. 在页面加载完毕后,调用render函数开始绘制烟花效果。 下面是一个简单的HTML+CSS烟花代码示例: HTML代码: ``` <canvas id="fireworks"></canvas> ``` CSS代码: ``` #fireworks { width: 100%; height: 100%; } ``` JS代码: ``` var canvas = document.getElementById('fireworks'); var ctx = canvas.getContext('2d'); // 粒子对象 function Particle(x, y, vx, vy, color) { this.x = x; this.y = y; this.vx = vx; this.vy = vy; this.color = color; } // 粒子数组 var particles = []; // 更新粒子对象 function update(particle) { particle.x += particle.vx; particle.y += particle.vy; particle.vy += 0.1; ctx.beginPath(); ctx.fillStyle = particle.color; ctx.arc(particle.x, particle.y, 5, 0, Math.PI * 2); ctx.fill(); } // 清空画布并更新粒子数组 function render() { ctx.clearRect(0, 0, canvas.width, canvas.height); particles.forEach(function(particle) { update(particle); }); requestAnimationFrame(render); } // 初始化粒子数组并开始绘制烟花效果 for (var i = 0; i < 50; i++) { particles.push(new Particle(canvas.width / 2, canvas.height, Math.random() * 6 - 3, Math.random() * -10 - 5, 'rgb(' + Math.floor(Math.random() * 256) + ',' + Math.floor(Math.random() * 256) + ',' + Math.floor(Math.random() * 256) + ')')); } render(); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值