Este artículo describe el método de implementación del efecto de fondo de fuegos artificiales JS. Compártelo para su referencia. El método de implementación específico es el siguiente:
La copia del código es la siguiente:
<! DocType html public "-// w3c // dtd xhtml 1.0 Transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transicional.dtd ">
<html xmlns = "http://www.w3.org/1999/xhtml">
<Evista>
<meta http-equiv = "content-type" content = "text /html; charset = utf-8" />
<title> otro efecto de fondo de fuegos artificial JS </title>
<script type = "text/javaScript">
VAR fuegos artificiales = function () {
this.size = 20;
this.rise ();
}
Fireworks.prototype = {
color: function () {
var c = ['0', '3', '6', '9' ',' c ',' f '];
var t = [c [math.floor (math.random ()*100)%6], '0', 'f'];
t.sort (function () {return math.random ()> 0.5? -1: 1;});
return '#'+t.Join ('');
},
adelante: function () {
var h = document.documentelement.clientHeight-250;
return math.abs (math.floor (math.random ()*h-200))+201;
},
Firecracker: function () {
var b = document.createElement ('div');
var w = document.documentelement.clientwidth;
B.Style.Position = 'Absolute';
b.style.color = this.color ();
b.style.bottom = 0;
b.style.left = math.floor (math.random ()*w)+1+'px';
document.body.appendChild (b);
regreso B;
},
Rise: function () {
var o = this.fireCracker ();
var n = this.Aheight ();
var c = this.color;
var e = this.expl;
var s = this.size;
var k = n;
var m = function () {
o.style.bottom = parsefloat (o.style.bottom)+k*0.1+'px';
k- = k*0.1;
if (k <2) {
ClearInterval (claro);
E (O, N, S, C);
}
}
o.innerhtml = '.';
if (parseint (o.style.bottom) <n) {
var claro = setInterval (m, 20);
}
},
Expl: función (o, n, s, c) {
var r = n/3, ri = n/6, ri = n/9;
var r = 0, ri = 0, rii = 0;
para (var i = 0; i <s; i ++) {
var span = document.createElement ('span');
var p = document.createElement ('i');
var a = document.createElement ('a');
span.style.position = 'Absolute';
span.style.fontSize = n/10+'PX';
span.style.left = 0;
span.style.top = 0;
span.innerhtml = '*';
p.style.position = 'Absolute';
p.style.left = 0;
p.style.top = 0;
p.innerhtml = '*';
A.Style.Position = 'Absolute';
A.style.left = 0;
a.style.top = 0;
a.innerhtml = '*';
o.appendChild (span);
o.appendchild (p);
o.appendchild (a);
}
función spr () {
r += r*0.1;
ri+= ri*0.06;
rii+= rii*0.06;
sp = o.getElementsBytagName ('span');
p = o.getElementsBytagName ('i');
a = o.getElementsBytagName ('a');
para (var i = 0; i <sp.length; i ++) {
sp [i] .style.color = c ();
p [i] .style.color = c ();
a [i] .style.color = c ();
sp [i] .style.left = r*math.cos (360/s*i)+'px';
sp [i] .style.top = r*math.sin (360/s*i)+'px';
sp [i] .style.fontSize = parsefloat (sp [i] .style.fontSize)*0.96+'px';
p [i] .style.left = ri*math.cos (360/s*i)+'px';
p [i] .style.top = ri*math.sin (360/s*i)+'px';
p [i] .style.fontSize = parsefloat (sp [i] .style.fontSize)*0.96+'PX';
a [i] .style.left = rii*math.cos (360/s*i)+'px';
a [i] .style.top = rii*math.sin (360/s*i)+'px';
a [i] .style.fontSize = parsefloat (sp [i] .style.fontSize)*0.96+'px';
}
R- = r*0.1;
if (r <2) {
o.innerhtml = '';
O.ParentNode.RemoVechild (O);
ClearInterval (Cleari);
}
}
var cleari = setInterval (spr, 20);
}
}
window.onload = function () {
función happyNewyear () {
nuevos fuegos artificiales ();
}
setInterval (HappyNewyear, 1000);
}
</script>
<style type = "text/css">
</style>
</ablo>
<Body style = "Background:#000; Font: 12px Georgia, 'Times New Roman', Times, Serif">
</body>
</html>
El efecto de operación es el siguiente:
Espero que este artículo sea útil para la programación de JavaScript de todos.