В этой статье описывается метод JS для достижения супер -крутых эффектов анимации веб -фейерверка. Поделитесь этим для вашей ссылки. Конкретный анализ заключается в следующем:
Эффект анимации настройки веб -фейерверков, реализованный с использованием JS, очень ослепитель, который может адаптироваться к JS для создания таких анимаций.
Скопируйте код следующим образом: <! 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">
<голова>
<название> Супер крутой эффект веб -фейерверка </title>
</head>
<стиль типа = "text/css">
.fire {Display: Block; переполнение: скрыто; размер шрифта: 12px; позиция: абсолют};
тело {переполнение: скрыто; Фон:#000}
html {overflow: hidden; Фон:#000}
</style>
<тело>
</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 = {
Приложение: function (parent) {
parent.appendchild (this.p);
},
setSize: function (Scale) {
this.p.style.fontsize = this.radius * Scale + "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? «Блок»: «Нет»;
}
}
var fireworks = function () {
var fires = new Array ();
var count = 150;
var fl = 250;
var vpx = 500;
var vpy = 300;
var Gravity = .5;
var floor = 200;
var Bounce = -.8;
var таймер;
var wind = ((math.floor (math.random ()*3) + 3)/10)*(math.random ()*2 - 1> 0? 1: -1)*. 25;
var wpos = 0;
var wcount;
возвращаться {
init: function () {
wcount = 50 + math.floor (math.random () * 100);
для (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 = новый огонь (12, цвет);
Fires.push (огонь);
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 that = это;
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;
}
для (var i = 0; i <count; i ++) {
это. (Fires [i]);
}
}, 30);
},
Движение: функция (огонь) {
Fire.vy += гравитация;
Fire.x += Fire.vx;
Fire.y += Fire.vy;
Fire.vx += ветер;
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>
Я надеюсь, что эта статья будет полезна для каждого программирования JavaScript.