百度降雪代码

Xhtml代码

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>下雪了</title>
<style type="text/css">
.snow{font-family:verdana;color:black;position:absolute;vertical-align:baseline;padding:0;margin:0;}
</style>
</head>

<body>
<div id="menu" class="menu ">

</div>
<script type="text/javascript" src="http://img.baidu.com/js/tangram-1.3.0.js"></script>
<script type="text/javascript">(function(){var V=984;var H,N;var W=[];var L;var P;var G=5;var R=10;var Q,M;var E;var J=false;var I=false;var O=false;var B=0;var S=0;var F=[];for(var U=0;U<4;U++){F.push(112+Math.random()*3)}function K(X,Y){this.dom=document.createElement("div");this.dom.innerHTML="*";this.frameIndex=0;this.x=Math.random()*(Y-R*2)+R/2;this.y=0;this.zoom=X;this.xSpeed=3;this.ySpeed=this.zoom*5+1;this.dom.className="snow";this.dom.style.fontSize=this.zoom*4+12+"px";this.frames=[{x:this.x,y:this.y}]}K.prototype.draw=function(){var Y=this.frames[this.frameIndex++];if(!Y){if(this.frames[this.frameIndex-2].remove){P.removeChild(this.dom)}return false}var X=this.dom.style;X.left=Y.x+"px";X.top=Y.y+"px";return true};K.prototype.update=function(){this.x+=this.xSpeed*Math.random();this.y+=this.ySpeed;if(this.x>L-R){this.x=R}else{if(this.x<R){this.x=L-R}}var X={x:this.x,y:this.y};return X};K.prototype.calculate=function(){while(this.y<F[parseInt(this.x)%4]){this.frames.push(this.update())}if(this.x<Q||this.x>M){for(var Y=0,X=80/this.ySpeed;Y<X;Y++){this.frames.push(this.update())}var Z=this.update();Z.remove=true;this.frames.push(Z)}else{if(J){this.frames.push({x:this.x,y:this.y,remove:true})}}};function C(X){var Z=[];for(var Y=0;Y<G;Y++){var a=new K(Math.random(),L);X.appendChild(a.dom);a.calculate();Z.push(a)}return Z}function D(){G=0}function A(){G=5}function T(){E=baidu.dom.create("div",{className:"snow-cover"});baidu.g("menu").appendChild(E);baidu.setStyle(baidu.g("menu"),"position","relative");P=document.createElement("div");P.className="container";document.body.appendChild(P);if(baidu.browser.ie){document.execCommand("BackgroundImageCache",false,true);baidu.setStyle(baidu.g("menu"),"zoom","1");P.onselectstart=function(){return false};document.onfocusout=D;document.onfocusin=A}else{window.onblur=D;window.onfocus=A}L=baidu.page.getWidth();Q=baidu.g("menu").offsetLeft-5;M=V+Q;N=setInterval(function(){if(I){return }var X=document.createDocumentFragment();W=W.concat(C(X));P.appendChild(X);S+=G;if(S>0){if(S===180*G){J=true;for(var Y=0;Y<4;Y++){F[Y]-=3}S=-10}else{if(S>50*G){B+=0.01*G/5;baidu.dom.setStyle(E,"opacity",B)}}}},300);H=setInterval(function(){if(I){return }for(var X=0;X<W.length;X++){if(!W[X].draw()){W.splice(X,1)}}},60)}window.onresize=function(){I=true;if(J){for(var X=0;X<4;X++){F[X]+=3}}J=false;S=0;B=0;W.length=0;P.innerHTML="";baidu.dom.setStyle(E,"opacity",0);setTimeout(function(){L=baidu.page.getWidth();Q=baidu.g("menu").offsetLeft-5;M=V+Q;I=false},500)};T()})();</script></body>
</html>

 js代码

 

(function() {
var V = 984;
var H,N;
var W = [];
var L;
var P;
var G = 5;
var R = 10;
var Q,M;
var E;
var J = false;
var I = false;
var O = false;
var B = 0;
var S = 0;
var F = [];
for (var U = 0; U < 4; U++) {
F.push(112 + Math.random() * 3)
}
function K(X, Y) {
this.dom = document.createElement("div");
this.dom.innerHTML = "*";
this.frameIndex = 0;
this.x = Math.random() * (Y - R * 2) + R / 2;
this.y = 0;
this.zoom = X;
this.xSpeed = 3;
this.ySpeed = this.zoom * 5 + 1;
this.dom.className = "snow";
this.dom.style.fontSize = this.zoom * 4 + 12 + "px";
this.frames = [
{x:this.x,y:this.y}
]
}

K.prototype.draw = function() {
var Y = this.frames[this.frameIndex++];
if (!Y) {
if (this.frames[this.frameIndex - 2].remove) {
P.removeChild(this.dom)
}
return false
}
var X = this.dom.style;
X.left = Y.x + "px";
X.top = Y.y + "px";
return true
};
K.prototype.update = function() {
this.x += this.xSpeed * Math.random();
this.y += this.ySpeed;
if (this.x > L - R) {
this.x = R
} else {
if (this.x < R) {
this.x = L - R
}
}
var X = {x:this.x,y:this.y};
return X
};
K.prototype.calculate = function() {
while (this.y < F[parseInt(this.x) % 4]) {
this.frames.push(this.update())
}
if (this.x < Q || this.x > M) {
for (var Y = 0,X = 80 / this.ySpeed; Y < X; Y++) {
this.frames.push(this.update())
}
var Z = this.update();
Z.remove = true;
this.frames.push(Z)
} else {
if (J) {
this.frames.push({x:this.x,y:this.y,remove:true})
}
}
};
function C(X) {
var Z = [];
for (var Y = 0; Y < G; Y++) {
var a = new K(Math.random(), L);
X.appendChild(a.dom);
a.calculate();
Z.push(a)
}
return Z
}

function D() {
G = 0
}

function A() {
G = 5
}

function T() {
E = baidu.dom.create("div", {className:"snow-cover"});
baidu.g("menu").appendChild(E);
baidu.setStyle(baidu.g("menu"), "position", "relative");
P = document.createElement("div");
P.className = "container";
document.body.appendChild(P);
if (baidu.browser.ie) {
document.execCommand("BackgroundImageCache", false, true);
baidu.setStyle(baidu.g("menu"), "zoom", "1");
P.onselectstart = function() {
return false
};
document.onfocusout = D;
document.onfocusin = A
} else {
window.onblur = D;
window.onfocus = A
}
L = baidu.page.getWidth();
Q = baidu.g("menu").offsetLeft - 5;
M = V + Q;
N = setInterval(function() {
if (I) {
return
}
var X = document.createDocumentFragment();
W = W.concat(C(X));
P.appendChild(X);
S += G;
if (S > 0) {
if (S === 180 * G) {
J = true;
for (var Y = 0; Y < 4; Y++) {
F[Y] -= 3
}
S = -10
} else {
if (S > 50 * G) {
B += 0.01 * G / 5;
baidu.dom.setStyle(E, "opacity", B)
}
}
}
}, 300);
H = setInterval(function() {
if (I) {
return
}
for (var X = 0; X < W.length; X++) {
if (!W[X].draw()) {
W.splice(X, 1)
}
}
}, 60)
}

window.onresize = function() {
I = true;
if (J) {
for (var X = 0; X < 4; X++) {
F[X] += 3
}
}
J = false;
S = 0;
B = 0;
W.length = 0;
P.innerHTML = "";
baidu.dom.setStyle(E, "opacity", 0);
setTimeout(function() {
L = baidu.page.getWidth();
Q = baidu.g("menu").offsetLeft - 5;
M = V + Q;
I = false
}, 500)
};
T()
})();

 原文出处:http://www.iteye.com/topic/1118689

posted @ 2016-05-17 15:42  横江东来  阅读(47)  评论(0)    收藏  举报