В этой статье описывается метод JavaScript для достижения эффекта рассеяния красочных снежинок с неба. Поделитесь этим для вашей ссылки. Конкретный анализ заключается в следующем:
Давайте сначала рассмотрим эффект бега, как показано на рисунке ниже:
Полный исходный код заключается в следующем:
Скопируйте код следующим образом: <! 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> javascript красочные снежинки падают с неба </title>
<стиль типа = "text/css">
.jb51snow {display: block; переполнение: скрыто; размер шрифта: 12px; позиция: абсолют};
Body {founfer:#000; маржа: 0px}
html {overflow: hidden; Фон:#000;}
a {color: белый; текстовый-декорация: нет}
.jb51title {цвет: красный; высота: 140px; ширина: 800px; маржа: 0px auto; text-align: center}
</style>
</head>
<тело>
<script type = "text/javascript">
var yanhua = "yanhua.vevb.com";
var fire = function (r, color) {
this.radius = r || 12;
this.color = color || "FF6600";
this.xpos = 0;
this.ypos = 0;
this.zpos = 0;
this.vx = 0;
this.vy = 0;
this.vz = 0;
this.mass = 1;
this.p = document.createElement ("span");
this.p.classname = "jb"+"51snow";
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 = 100;
var fl = 250;
var vpx = 500;
var vpy = 300;
var Gravity = .3;
var floor = 200;
var Bounce = -.8;
var таймер;
возвращаться {
init: function () {
для (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.vx = math.random () * 6 - 3;
fire.vy = math.random () * 6 - 3;
fire.vz = math.random () * 6 - 3;
fire.append (document.body);
}
var that = это;
timer = setInterval (function () {
для (var i = 0; i <count; i ++) {
это. (Fires [i]);
}
}, 30);
},
Движение: функция (огонь) {
Fire.vy += гравитация;
Fire.xpos += Fire.vx;
Fire.ypos += Fire.vy;
fire.zpos += Fire.vz;
if (fire.ypos> пол) {
Fire.ypos = пол;
fire.vy *= отскочить;
}
if (fire.zpos> -fl) {
var scale = fl / (fl + fire.zpos);
Fire.setize (Scale);
Fire.SetPosition (vpx + fire.xpos * Scale,
vpy + fire.ypos * Scale);
Fire.SetVisible (True);
} еще {
Fire.SetVisible (false);
}
}
}
}
if (yanhua === 'yanhua.jb' + '51. ' +' net ')
Fireworks (). init ();
функция jb51snow () {
window.location.reload ();
} if (yanhua === 'yanhua.jb' + '51. ' +' net ')
SetInterval (JB51Snow, 6000);
</script>
</body>
</html>
Я надеюсь, что эта статья будет полезна для каждого программирования JavaScript.