Artikel ini menjelaskan metode JS untuk mencapai efek animasi firework web yang sangat keren. Bagikan untuk referensi Anda. Analisis spesifiknya adalah sebagai berikut:
Efek animasi pengaturan kembang api web yang diimplementasikan menggunakan JS sangat mempesona, yang dapat beradaptasi dengan JS untuk membuat animasi tersebut.
Salin kode sebagai berikut: <! Doctype html public "-// w3c // dtd xhtml 1.0 transisi // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title> Efek kembang api web super keren </iteme>
</head>
<type style = "text/css">
.fire {display: block; meluap: tersembunyi; font-size: 12px; Posisi: Absolute};
tubuh {overflow: tersembunyi; Latar belakang:#000}
html {overflow: tersembunyi; Latar belakang:#000}
</tyle>
<body>
</body>
<type skrip = "Teks/JavaScript">
var fire = function (r, color) {
this.radius = r || 12;
this.color = warna;
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 = {
append: function (parent) {
Parent.AppendChild (this.p);
},
setsize: function (skala) {
this.p.style.fontsize = this.radius * skala + "px";
},
setPosition: function (x, y) {
this.p.style.left = x + "px";
this.p.style.top = y + "px";
},
setVisible: function (b) {
this.p.style.display = b? "blok": "tidak ada";
}
}
var fireworks = function () {
var fires = array baru ();
var count = 150;
var fl = 250;
var vpx = 500;
var vpy = 300;
var gravitasi = .5;
Lantai var = 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;
kembali {
init: function () {
wcount = 50 + math.floor (math.random () * 100);
untuk (var i = 0; i <count; i ++) {
Warna var = 0xff0000;
color = (math.random () * 0xffffff) .toString (16) .tostring (). split (".") [0];
while (color.length <6) {
warna = "0" + warna;
}
var fire = api baru (12, warna);
fires.push (api);
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 itu = ini;
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;
}
untuk (var i = 0; i <count; i ++) {
itu.move (api [i]);
}
}, 30);
},
pindahkan: function (fire) {
fire.vy += gravitasi;
fire.x += fire.vx;
fire.y += fire.vy;
fire.vx += angin;
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);
}
}
}
}
kembang api (). init ();
</script>
</html>
Saya harap artikel ini akan membantu pemrograman JavaScript semua orang.