Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize five kinds of fireworks special effects by JavaScript

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will introduce in detail for you "JavaScript how to achieve five different fireworks effects", the content steps are clear and detailed, the details are handled properly, and the editor will update different knowledge points every day. I hope this article "JavaScript how to achieve five different fireworks effects" can give you unexpected gains, please follow the editor's ideas slowly in depth, the specific content is as follows, to harvest new knowledge.

I. simple and atmospheric fireworks

Demo address: http://haiyong.site/fireworks1

HTML Code:

The HTML code here is very short.

CSS code

These are the only two paragraphs of css.

Body {background:black; overflow:hidden; margin:0;} canvas {background:#000;}

JS code

All the source code is here, just copy and paste

Window.addEventListener ("resize", resizeCanvas, false); window.addEventListener ("DOMContentLoaded", onLoad, false); window.requestAnimationFrame = window.requestAnimationFrame | | window.webkitRequestAnimationFrame | | window.mozRequestAnimationFrame | | window.oRequestAnimationFrame | | window.msRequestAnimationFrame | | function (callback) {window.setTimeout (callback, 1000 Universe 60);}; var canvas, ctx, w, h, particles = [], probability = 0.04, xPoint, yPoint; function onLoad () {canvas = document.getElementById ("canvas") Ctx = canvas.getContext ("2d"); resizeCanvas (); window.requestAnimationFrame (updateWorld);} function resizeCanvas () {if (!! canvas) {w = canvas.width = window.innerWidth; h = canvas.height = window.innerHeight;}} function updateWorld () {update (); paint (); window.requestAnimationFrame (updateWorld);} function update () {if (particles.length)

< 500 && Math.random() < probability) { createFirework(); } var alive = []; for (var i=0; i= screen.height || this.alpha = 0; i--){ maxOpacity = Math.max(maxOpacity, this.fireworks[i].getOpacity()); } contextTwigs.clearRect(0, 0, this.width, this.height); contextFireworks.fillStyle = this.SKY_COLOR.replace('%luminance', 5 + maxOpacity * 15); contextFireworks.fillRect(0, 0, this.width, this.height); for(var i = this.fireworks.length - 1; i >

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report