var flake = ''; $(window).on('load', function() { interval = setInterval(function() { create_snow_lake(); remove_snow_lake(); },200); }); function create_snow_lake(){ var falling_time = Math.floor(Math.random() * 10) + 5 ; var flake_pos = Math.floor(Math.random() * 90) + 4 ; var flake_size = (Math.floor(Math.random() * 100) + 1)/100 ; var snow_flake = "
"+ flake +"
"; $(snow_flake).appendTo('.background'); } function remove_snow_lake(){ $(".flake-wrapper").each(function(){ var flake_pos = $(this).offset().top; var body_height = $(document).height()-100; if( flake_pos > body_height){ $(this).remove(); } }); }