In this post I will show you how to create a raining effect using JavaScript. We will be using a JavaScript library called as Rainyday. We will also see how it works.
View Demo
Implementation
Rainyday creates the rainy effect inside a canvas and then positions the canvas over a given image.
This is the sample example code:
<!DOCTYPE html>
<html>
<head>
<title>Awesome Rainy Effect</title>
<style media="screen">
body {
overflow: hidden;
height: 100%;
margin: 0;
padding: 0;
}
img {
width: 100%;
height: 100%;
}
</style>
<script src="rainday.js"></script>
<script>
function loaded_image(img)
{
var engine = new RainyDay({image: img});
engine.rain([ [1, 2, 8000] ]);
engine.rain([ [3, 3, 0.88], [5, 5, 0.9], [6, 2, 1] ], 100);
}
</script>
</head>
<body>
<img id="background" src="rain-forest.jpg" onload="loaded_image(this)" />
</body>
</html>
<html>
<head>
<title>Awesome Rainy Effect</title>
<style media="screen">
body {
overflow: hidden;
height: 100%;
margin: 0;
padding: 0;
}
img {
width: 100%;
height: 100%;
}
</style>
<script src="rainday.js"></script>
<script>
function loaded_image(img)
{
var engine = new RainyDay({image: img});
engine.rain([ [1, 2, 8000] ]);
engine.rain([ [3, 3, 0.88], [5, 5, 0.9], [6, 2, 1] ], 100);
}
</script>
</head>
<body>
<img id="background" src="rain-forest.jpg" onload="loaded_image(this)" />
</body>
</html>