Skip to content

Instantly share code, notes, and snippets.

@kswedberg
Created December 17, 2010 17:12
Show Gist options
  • Save kswedberg/745293 to your computer and use it in GitHub Desktop.
Save kswedberg/745293 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
$.fx.interval = 24;
var $flakes = $('span.flake'),
rand = Math.random,
ceil = Math.ceil,
windowWidth = $(window).width(),
land = $(document).height() - 295,
multipliers = [5,6,8,12,16],
mLength = multipliers.length,
randomIndex = function() {
return Math.floor(Math.random() * mLength);
};
var fallingSnow = function(elem, opts) {
var $flake = $(elem);
$flake.css({
top: '-40px',
left: function() {
return ceil(rand() * (windowWidth - opts.flakeWidth));
}
});
setTimeout(function() {
$flake.animate({top: land + 'px'}, opts.speed*multipliers[randomIndex()], function() {
fallingSnow(elem, $flake.data('options'));
});
}, opts.timeout*multipliers[randomIndex()]);
};
$(window).bind('load', function(event) {
$flakes.each(function() {
$(this).data('options', {
speed: 1500,
timeout: 250,
flakeWidth: 20
});
fallingSnow(this, $(this).data('options'));
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment