Ajax Loader
HTML
<canvas id='display' width='1' height='1'/>
1
<canvas id='display' width='1' height='1'/>
 
CSS
body{
1
body{
2
  background:#111;
3
  color:white;
4
  overflow:hidden;
5
  padding:0;
6
  margin:0;
7
}
 
JavaScript
//just tweaking @hunterloftis demo for some NeatNait rain particles
1
//just tweaking @hunterloftis demo for some NeatNait rain particles
2
//credits goes -> http://www.playfuljs.com/particle-effects-are-easy/
3
 
4
var DAMPING = 0.999;
5
var GRAVITY = 0.2;
6
var MAXAGE = 200;
7
 
8
function Particle(x, y) {
9
  this.x = this.oldX = x;
10
  this.y = this.oldY = y;
11
  this.age = 0;//added age
12
}
13
 
14
Particle.prototype.integrate = function() {
15
  var velocity = this.getVelocity();
16
  this.oldX = this.x;
17
  this.oldY = this.y;
18
  this.x += velocity.x * DAMPING;
19
  this.y += velocity.y * DAMPING;
20
};
21
 
22
Particle.prototype.getVelocity = function() {
23
  return {
24
    x: this.x - this.oldX,
25
    y: this.y - this.oldY
26
  };
27
};
28
 
29
Particle.prototype.move = function(x, y) {
30
  this.x += x;
31
  this.y += y;
32
  this.age++;
33
};
34
 
35
Particle.prototype.bounce = function() {
36
  if (this.y > height) {
37
    var velocity = this.getVelocity();
38
    this.oldY = height;
39
    this.y = this.oldY - velocity.y * Math.random()*0.2;
40
  }
41
};
42
 
43
//remove items if age is greater than MAXAGE threshold
44
Particle.prototype.remove = function(arr) {
45
  if (this.age > MAXAGE) {
46
    arr.splice(arr.indexOf(this), 1);
47
  }
48
};
49
 
50
Particle.prototype.draw = function() {
51
  ctx.strokeStyle = '#f06';
52
  ctx.lineWidth = 1;
53
  ctx.beginPath();
54
  ctx.moveTo(this.oldX, this.oldY);
55
  ctx.lineTo(this.x, this.y);
56
  ctx.stroke();
57
};
58
 
59
var display = document.getElementById('display');
60
var ctx = display.getContext('2d');
61
var drops = [];
62
var width = display.width = window.innerWidth;
63
var height = display.height = window.innerHeight;
64
 
65
ctx.globalCompositeOperation = 'overlay';
66
requestAnimationFrame(frame);
67
 
68
var z = -5;
69
 
70
function frame() {
71
  requestAnimationFrame(frame);
72
  ctx.clearRect(0, 0, width, height);
73
  for (var j = 0; j < 5; j++) {
74
    var drop = new Particle(width * 0.5, 0);
75
    drop.move(Math.random() * 8 - 4, -10);
76
    drops.push(drop);
77
  }
78
  for (var i = 0; i < drops.length; i++) {
79
    drops[i].integrate();
80
    drops[i].move(0, GRAVITY);
81
    drops[i].bounce();
82
    drops[i].draw();
83
    drops[i].remove(drops);//killing old particles
84
  }
85
}
86
 
 

Rain

CSSDeck G+