Este artigo descreve o método de implementação do efeito de fundo do JS Firework. Compartilhe para sua referência. O método de implementação específico é o seguinte:
A cópia do código é a seguinte:
<! Doctype html public "-// w3c // dtd xhtml 1.0 transitional // pt" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-bransitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text /html; charset = utf-8" />
<title> Outro efeito legal de Firework Backgry de Fogo JS </title>
<script type = "text/javascript">
VAR Fireworks = function () {
this.size = 20;
this.rise ();
}
Fireworks.prototype = {
Cor: 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 ('');
},
ADIENTE: 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);
retornar b;
},
ascensão: 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 clear = setInterval (m, 20);
}
},
Expl: function (o, n, s, c) {
var r = n/3, ri = n/6, ri = n/9;
var r = 0, ri = 0, rii = 0;
for (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);
}
function 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');
for (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 () {
função happynewyear () {
novos fogos de artifício ();
}
setInterval (happynewyear, 1000);
}
</script>
<style type = "text/css">
</style>
</head>
<Body style = "Antecedentes:#000; Fonte: 12px Geórgia, 'Times New Roman', Times, Serif">
</body>
</html>
O efeito de operação é o seguinte:
Espero que este artigo seja útil para a programação JavaScript de todos.