Dieser Artikel beschreibt die Methode von JS, um super coole Web -Firework -Animationseffekte zu erzielen. Teilen Sie es für Ihre Referenz. Die spezifische Analyse ist wie folgt:
Ein mit JS implementierter Web -Fireworks -Setting -Animationseffekt ist sehr schillernd, was sich an JS anpassen kann, um solche Animationen zu erstellen.
Kopieren Sie den Code wie folgt: <! 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">
<kopf>
<titels> Super cooles Webfeuerwerk Effekt </title>
</head>
<style type = "text/css">
.fire {display: block; Überlauf: versteckt; Schriftgröße: 12px; Position: absolut};
Körper {Überlauf: versteckt; Hintergrund:#000}
html {Überlauf: versteckt; Hintergrund:#000}
</style>
<body>
</body>
<script type = "text/javaScript">
var fire = function (r, color) {
this.radius = r || 12;
this.color = color;
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;
}
Fire.prototype = {
Anhang: Funktion (übergeordnet) {
parent.Appendchild (this.p);
},
setSize: function (scale) {
this.p.style.fontsize = this.radius * scale + "px";
},
SetPosition: Funktion (x, y) {
this.p.style.left = x + "px";
this.p.style.top = y + "px";
},
setvisible: function (b) {
this.p.style.display = b? "Block": "keine";
}
}
var fireworks = function () {
var fires = 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 Timer;
var wind = ((math.floor (math.random ()*3) + 3)/10)*(math.random ()*2 - 1> 0? 1: -1)*. 25;
var wpos = 0;
var wcount;
zurückkehren {
init: function () {
WCount = 50 + math.floor (math.random () * 100);
für (var i = 0; i <count; i ++) {
var color = 0xff0000;
color = (math.random () * 0xffffff) .ToString (16) .ToString (). Split (".") [0];
while (color.length <6) {
color = "0" + color;
}
var fire = neues feuer (12, Farbe);
fires.push (feuer);
fire.ypos = -100;
fire.vz = math.random () * 6 - 3;
fire.vx = (math.random ()*2 - 1)*2;
fire.vy = math.random ()* - 15 - 15;
fire.x = 500
fire.y = 600;
fire.Append (document.body);
}
var das = dies;
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;
}
für (var i = 0; i <count; i ++) {
that.move (feuert [i]);
}
}, 30);
},
Bewegung: Funktion (Feuer) {
fire.Vy += Schwerkraft;
fire.x += fire.vx;
fire.y += fire.vy;
fire.vx += wind;
fire.setPosition (fire.x, fire.y);
if (fire.x <0 || fire.x> 1000 || fire.y <0 || fire.y> 600) {
fire.vx = (math.random ()*2 - 1)*2;
fire.vy = math.random ()* - 15 - 15;
fire.x = 500;
fire.y = 600;
fire.setPosition (fire.x, fire.y);
}
}
}
}
Fireworks (). init ();
</script>
</html>
Ich hoffe, dieser Artikel wird für JavaScript -Programme aller hilfreich sein.