Skip to content

Commit

Permalink
Merge pull request #1 from mchateloin/master
Browse files Browse the repository at this point in the history
Just some small stuff with options
  • Loading branch information
joshmcrty committed Dec 4, 2013
2 parents 2292799 + 9958b0f commit 018ebb9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ Options

`variance` controls how much each flake will randomly drift in pixels using the `wind` as a base

`preventScrolls` determines whether `overflow-x: auto` is applied to the `html` element to prevent horizontal scrolling
`preventScrolls` determines whether `overflow-x: auto` is applied to the `html` element to prevent horizontal scrolling

`character` determines the character or html entity to be replicated as a snowflake

`transparency` determines the alpha value of color of the character
27 changes: 27 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<html>
<head>
<style>
body{
background: darkblue;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="jquery.flurry.js"></script>
</head>
<body>
<script>
$( document ).ready( function() {
$().flurry({
height: 1000,
speed: 3000,
wind: 400,
variance: 100,
large: 75,
small: 25,
density: 1,
transparency: 0.4
});
});
</script>
</body>
</html>
29 changes: 16 additions & 13 deletions jquery.flurry.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@
* @copyright 2013 Josh McCarty
* @license https://github.com/joshmcrty/Flurry/blob/master/LICENSE GPLv2
*/
( function( $ ) {
;( function( $, window ) {

$.fn.flurry = function( options ) {

// Settings
var settings = $.extend({
height: 150,
density: 100,
speed: 3000,
small: 12,
large: 20,
wind: 40,
variance: 20,
preventScroll: true
height: 150,
density: 100,
speed: 3000,
small: 12,
large: 20,
wind: 40,
variance: 20,
preventScroll: true,
character: "&bull;",
transparency: 1
}, options );

// Prevent browser horizontal scrolling
Expand All @@ -41,17 +43,17 @@
var randomNumberInRange = function( min, max ) {
return Math.random() * ( max - min ) + min;
};

// Create and animate a flake
var createFlake = function() {

// Set the flake's starting position to a random number between the window width, including additional space for the wind setting
var left = randomNumberInRange( 0 - Math.abs( settings.wind ), windowWidth + Math.abs( settings.wind ) );

// Create the flake, set the CSS for it, and animate it
var flake = '<span>&bull;</span>';
var flake = '<span>' + settings.character + '</span>';
$( flake ).css({
"color": "#FFF",
"color": "rgba(255, 255, 255, " + settings.transparency + ")",
"font-size": randomNumberInRange( settings.small, settings.large ) + "px",
"position": "absolute",
"top": "-" + settings.large + "px",
Expand All @@ -64,9 +66,10 @@
}, randomNumberInRange( settings.speed - 400, settings.speed + 400 ), "linear", function() {
$( this ).remove();
});

};

// Generate flakes at the interval set by the density setting
setInterval( createFlake, settings.density );
};
}( jQuery ));
}( jQuery, window, undefined ));

0 comments on commit 018ebb9

Please sign in to comment.