Cet article décrit la méthode de JS pour réaliser des effets d'animation de feu d'artifice super cool. Partagez-le pour votre référence. L'analyse spécifique est la suivante:
Un effet d'artifice Web définissant l'effet d'animation implémenté à l'aide de JS est très éblouissant, qui peut s'adapter à JS pour créer de telles animations.
Copiez le code comme suit: <! Doctype html public "- // w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<adal>
<Title> Effet de feu d'artifice Web super cool </TITAL>
</ head>
<style type = "text / css">
.fire {affichage: bloc; débordement: caché; taille de police: 12px; position: absolu};
corps {débordement: caché; Contexte: # 000}
html {overflow: Hidden; Contexte: # 000}
</ style>
<body>
</docy>
<script type = "text / javascript">
var feu = fonction (r, couleur) {
this.radius = r || 12
this.color = couleur;
this.xpos = 0;
this.ypos = 0;
this.zpos = 0;
this.vx = 0;
this.vy = 0;
this.vz = 0;
this.mass = 1;
this.x = 0;
this.y = 0;
this.p = document.CreateElement ("Span");
this.p.classname = "fire";
this.p.innerhtml = "*";
this.p.style.fontsize = this.radius + "px";
this.p.style.color = "#" + this.color;
}
Feu.prototype = {
Ajouter: fonction (parent) {
Parent.ApendChild (this.p);
},
setSize: fonction (échelle) {
this.p.style.fontsize = this.radius * échelle + "px";
},
setPosition: fonction (x, y) {
this.p.style.left = x + "px";
this.p.style.top = y + "px";
},
setVisible: fonction (b) {
this.p.style.display = b? "Block": "Aucun";
}
}
var Fireworks = function () {
var feux = new Array ();
Var Count = 150;
var fl = 250;
var vpx = 500;
var vpy = 300;
Var Gravity = 0,5;
Var Floor = 200;
var Bounce = -.8;
var temporisateur;
var wind = ((math.floor (math.random () * 3) + 3) / 10) * (math.random () * 2 - 1> 0? 1: -1) *. 25;
var wpos = 0;
var wCount;
retour {
init: function () {
wCount = 50 + math.floor (math.random () * 100);
pour (var i = 0; i <count; i ++) {
var color = 0xff0000;
color = (math.random () * 0xffffff) .toString (16) .toString (). Split (".") [0];
while (colore.length <6) {
color = "0" + couleur;
}
Var Fire = nouveau feu (12, couleur);
Fires.push (incendie);
feu.ypos = -100;
feu.vz = math.random () * 6 - 3;
feu.vx = (math.random () * 2 - 1) * 2;
feu.vy = math.random () * - 15 - 15;
feu.x = 500
feu.y = 600;
Fire.APPEND (document.body);
}
var that = this;
timer = setInterval (function () {
WPOS ++;
if (wpos> = wCount) {
WPOS = 0;
wCount = 50 + math.floor (math.random () * 100);
wind = ((math.floor (math.random () * 3) + 3) / 10) * (math.random () * 2 - 1> 0? 1: -1) *. 25;
}
pour (var i = 0; i <count; i ++) {
that.move (feux [i]);
}
}, 30);
},
Déplacer: fonction (feu) {
Fire.vy + = Gravity;
feu.x + = feu.vx;
feu.y + = feu.vy;
feu.vx + = vent;
Fire.SetPosition (Fire.x, Fire.Y);
if (fire.x <0 || fire.x> 1000 || fire.y <0 || fire.y> 600) {
feu.vx = (math.random () * 2 - 1) * 2;
feu.vy = math.random () * - 15 - 15;
feu.x = 500;
feu.y = 600;
Fire.SetPosition (Fire.x, Fire.Y);
}
}
}
}
Fireworks (). init ();
</cript>
</html>
J'espère que cet article sera utile à la programmation JavaScript de tous.