(function($){ var $snow = $('<div id="snowBox" />').css({'position': 'absolute', 'top': '-50px'}).html('❄'); var h = $(document).height(); var w = $(document).width(); var t = setInterval( function(){ var startPositionLeft = Math.random() * w - 100, startOpacity = 0.5 + Math.random(), sizeFlake = 10 + Math.random() * 30, endPositionTop = h - 40, endPositionLeft = startPositionLeft - 100 + Math.random() * 500, durationFall = h * 10 + Math.random() * 4000; $snow.clone().appendTo('body').css({ 'left': startPositionLeft, 'opacity': startOpacity, 'font-size': sizeFlake, 'color': '#ffffff' }).animate({ 'top': endPositionTop, 'left': endPositionLeft, 'opacity': 0.2 },durationFall,'linear',function(){ $(this).remove(); }); }, 1000); })(jQuery);
body{background:#222222 url(http://www.17sucai.com/upload/32215/2013-10-23/eb32c1fb998feb6576dab0cfac50f32a.jpg) no-repeat center center;background-size:cover; color:#ccc;height:750px;overflow-x:hidden;}