Animation: snow : Animation « GUI Components « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Dojo toolkit
7. Event
8. Event onMethod
9. Ext JS
10. Form Control
11. GUI Components
12. HTML
13. Javascript Collections
14. Javascript Objects
15. Javascript Properties
16. jQuery
17. Language Basics
18. Mochkit
19. Mootools
20. Node Operation
21. Object Oriented
22. Page Components
23. Rico
24. Scriptaculous
25. Security
26. SmartClient
27. Style Layout
28. Table
29. Utilities
30. Window Browser
31. YUI Library
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
JavaScript DHTML » GUI Components » Animation 
Animation: snow
 
//Snow - http://www.btinternet.com/~kurt.grigg/javascript

/*
Paste this link as the last thing on your page, just before </body></html>

<script type="text/javascript" src="snow.js"></script>


To edit, right click on the snow.js file icon and choose edit.

Make sure the snow.js file is in/uploaded to the same directory/folder as 
the web page using it!

*/

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<title>Snow</title>

<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="content-script-type" content="text/javascript">
<meta http-equiv="content-style-type" content="text/css">

<style type="text/css">
<!--
body{
background : #000000;
}
//-->
</style>

</head>
<body>



<script type="text/javascript">
//Snow - http://www.btinternet.com/~kurt.grigg/javascript

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

(function(){

//Configure here.

var num = 30;   //Number of flakes
var timer = 30//setTimeout speed. Varies on different comps

//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(+ 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[i0;
fall[i(sfs[i== 1)?
Math.round(+ Math.random() 2): Math.round(+ Math.random() 2);
step[i(sfs[i== 1)?
0.05 + Math.random() 0.1 0.05 + Math.random() 0.05 ;
}


if (domWwr = 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(+ Math.random() 2): Math.round(+ 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.
</script>

</body>
</html>

           
         
  
Related examples in the same category
1. Attack animation
2. Circle Animation
3. Right to left animation
4. Flash animation in Javascript
5. Flash animation in JavaScript: Changing style Properties
6. Animation along Straight Line
7. Animation along a Circle
8. Dancing Text (IE)
9. Type Writer effect (IE)
10. Type Writer Effect 1.1 (IE)
11. JavaScript Ticker 1.2 (IE)
12. Animation: Lottery Number Picker and Statistics
13. Animation: wriggly
14. Animation: welcome message
15. Animation: trio
16. Auto lotto dip
17. Animation: star
18. Animation: mouse doodle
19. Animation: fireworks
20. Animation: pretty
21. Animation: Random Movement
22. Lotto number draw
23. Following eyes
24. Animation: three eyes
25. Animation: eyes
26. Spot light
27. Big static eyes
28. Animation based on DIV with color flash
29. Framework for creating CSS-based animations
30. Animate dynamic element h1 tag
31. Popup window animation (fly across screen)
32. Animation on several images
33. Using the onFilterChange Event Handler
34. JavaScript Animation
35. Periodically Updating the Text Displayed by an HTML Element
36. Moving an Airplane Across a Web Page
37. Link Hint Scroller 2.0 (IE)
38. Snow animation
39. Animation with JSTween
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.