Code tạo mưa tuyết

[Không rõ 2009/01/11 16:03 | by admin ]
Với đoạn mã code sau bạn chỉ cần nhét vào notepad và save lại với tên snow.js là đã xong bước 1

//Snow - http://www.btinternet.com/~kurt.grigg/javascript

if  ((document.getElementById) &&
window.addEventListener || window.attachEvent){

(function(){

//Configure here.

var num = 90;   //Number of flakes
var timer = 90; //setTimeout speed. Varies on different comps
var enableinNS6 = 1 //Enable script in NS6/Mozilla? Snow animation could be slow in those browsers. (1=yes, 0=no).

//End.

var y = [];
var x = [];
var fall = [];
var theFlakes = [];
var sfs = [];
var step = [];
var currStep = [];
var h,w,r;
var d = document;
var pix = "px";
var domWw = (typeof window.innerWidth == "number");
var domSy = (typeof window.pageYOffset == "number");
var idx = d.getElementsByTagName('div').length;

if (d.documentElement.style &&
typeof d.documentElement.style.MozOpacity == "string")
num = 12;

for (i = 0; i < num; i++){
sfs[i] = Math.round(1 + Math.random() * 1);

document.write('<div id="flake'+(idx+i)+'" style="position:absolute;top:0px;left:0px;width:'
+sfs[i]+'px;height:'+sfs[i]+'px;background-color:#ffffff;font-size:'+sfs[i]+'px"><\/div>');

currStep[i] = 0;
fall[i] = (sfs[i] == 1)?
Math.round(2 + Math.random() * 2): Math.round(3 + Math.random() * 2);
step[i] = (sfs[i] == 1)?
0.05 + Math.random() * 0.1 : 0.05 + Math.random() * 0.05 ;
}


if (domWw) r = window;
else{
  if (d.documentElement &&
  typeof d.documentElement.clientWidth == "number" &&
  d.documentElement.clientWidth != 0)
  r = d.documentElement;
else{
  if (d.body &&
  typeof d.body.clientWidth == "number")
  r = d.body;
}
}


function winsize(){
var oh,sy,ow,sx,rh,rw;
if (domWw){
  if (d.documentElement && d.defaultView &&
  typeof d.defaultView.scrollMaxY == "number"){
  oh = d.documentElement.offsetHeight;
  sy = d.defaultView.scrollMaxY;
  ow = d.documentElement.offsetWidth;
  sx = d.defaultView.scrollMaxX;
  rh = oh-sy;
  rw = ow-sx;
}
else{
  rh = r.innerHeight;
  rw = r.innerWidth;
}
h = rh - 2;  
w = rw - 2;
}
else{
h = r.clientHeight - 2;
w = r.clientWidth - 2;
}
}


function scrl(yx){
var y,x;
if (domSy){
y = r.pageYOffset;
x = r.pageXOffset;
}
else{
y = r.scrollTop;
x = r.scrollLeft;
}
return (yx == 0)?y:x;
}


function snow(){
var dy,dx;

for (i = 0; i < num; i++){
dy = fall[i];
dx = fall[i] * Math.cos(currStep[i]);

y[i]+=dy;
x[i]+=dx;

if (x[i] >= w || y[i] >= h){
  y[i] = -10;
  x[i] = Math.round(Math.random() * w);
  fall[i] = (sfs[i] == 1)?
  Math.round(2 + Math.random() * 2): Math.round(3 + Math.random() * 2);
  step[i] = (sfs[i] == 1)?
  0.05 + Math.random() * 0.1 : 0.05 + Math.random() * 0.05 ;
}

theFlakes[i].top = y[i] + scrl(0) + pix;
theFlakes[i].left = x[i] + scrl(1) + pix;

currStep[i]+=step[i];
}
setTimeout(snow,timer);
}


function init(){
winsize();
for (i = 0; i < num; i++){
theFlakes[i] = document.getElementById("flake"+(idx+i)).style;
y[i] = Math.round(Math.random()*h);
x[i] = Math.round(Math.random()*w);
}
snow();
}


if (window.addEventListener){
window.addEventListener("resize",winsize,false);
window.addEventListener("load",init,false);
}  
else if (window.attachEvent){
window.attachEvent("onresize",winsize);
window.attachEvent("onload",init);
}

})();
}//End.

Bước 2 khi bạn mún mưa tuyết rơi ở đâu chỉ cần thêm 1 đoạn mã java này liên kết đến tệp snow.js mà thôi

<script language="javascript" src="images/snow.js"></script>
Tập tin snow.js bạn có thể download tại đây :

Tệp tin tải về


Bài viết mới Bài viết ngẫu nhiên
  • CSS Làm nóc nhà Blog...
  • Auto Pk kiếm thế V 1...
  • Cách biến Windows V...
  • Album Vol1 guitar 20...
  • Nhạc hot tháng 3-201...
  • Thơ mừng 8-3 women&#...
  • Phim sóng thần 2022 ...
  • Code HTML chèn tin t...
  • Hướng dẫn mở khóa cá...
  • Counter-Strike 1.6
  • Game Globy 3D phiêu ...
  • Cách thắt cà vạt đẹp...
  • Nhạc hot tháng 2-201...
  • Phim Thần Thoại, Hồ ...
  • Ảnh Valentine đẹp và...
  • Thứ 6 ngày 13
  • DFX Audio Enhancer 9...
  • CD-ROM Giáo trình Ac...
  • Angkor, ngôi nhà của...
  • Share code Pikachu o...
  • Win7codecs 1.3.6 Fin...
  • Tránh bị lừa khi mua...
  • Age of Empires 1.0+ ...
  • Bí ẩn về bức họa 500...
  • Cài themes cho iPhon...
  • Biển số xe các tỉnh ...
  • IDM 5.18 Internet do...
  • Windows SP3 Xp-Vista...
  • Windows Xp Themes (c...
  • 1.000.000 key, seri...

  • By: admin
    Online in:
    Anhcong.net

    Anhcong.net Sharing all for you
    A winter without you!

    Happy funny by Anhcong.net!

    Tags:
    Code-Design web | Nhận xét(0) | Trích dẫn(0) | Đọc(297)
    Viết nhận xét
    Hình vui
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    Mở HTML
    Mở UBB
    Mở hình vui
    Ẩn giấu
    Hãy nhớ
    Tên gọi   Mật khẩu   Khách không cần mật khẩu
    Địa chỉ web   Email   [Đăng ký]