JavaScript to realize the effect of colorful snowflakes falling from sky _javascript tips

Source: Internet
Author: User
Tags setinterval

This article illustrates the way that JavaScript realizes the effect of colorful snowflakes falling from sky. Share to everyone for your reference. The specific analysis is as follows:

Let's take a look at the effect, as shown in the following illustration:

The complete source code is as follows:

Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>javascript colorful snowflakes from the sky down </title>
<style type= "Text/css" >
. jb51snow{display:block; overflow:hidden; font-size:12px; Position:absolute};
Body{background: #000; margin:0px}
Html{overflow:hidden; background: #000;}
A{color:white;text-decoration:none}
. jb51title{color:red;height:140px;width:800px;margin:0px Auto;text-align:center}
</style>

<body>

<script type= "Text/javascript" >
var Yanhua = "Yanhua.jb51.net";
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 = {
Append: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? "Block": "None";
}
}
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 timer;
return {
Init:function () {
for (var i = 0; i < count; i++) {
var color = 0xff0000;
color = (Math.random () * 0xFFFFFF). ToString (). ToString (). Split (".") [0];
while (Color.length < 6) {
color = "0" + color;
}
var fire = new Fire (color);
Fires.push (fire);
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 = this;
Timer = setinterval (function () {
for (var i = 0; i < count; i++) {
That.move (Fires[i]);
}
}, 30);
},
Move:function (Fire) {
Fire.vy + = gravity;
Fire.xpos + = FIRE.VX;
Fire.ypos + = Fire.vy;
Fire.zpos + = Fire.vz;
if (Fire.ypos > Floor) {
Fire.ypos = floor;
Fire.vy *= Bounce;
}
if (Fire.zpos >-FL) {
var scale = FL/fl + fire.zpos;
Fire.setsize (scale);
Fire.setposition (VPX + fire.xpos * scale,
Vpy + fire.ypos * scale);
Fire.setvisible (TRUE);
} else {
Fire.setvisible (FALSE);
}
}
}
}
if (Yanhua = = ' yanhua.jb ' + '. ' + ' + ']
Fireworks (). Init ();

function Jb51snow () {
Window.location.reload ();
if (Yanhua = = ' Yanhua.jb ' + ' + ' + ' + ')
SetInterval (Jb51snow, 6000);
</script>

</body>

I hope this article will help you with your JavaScript programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.