(function($){
$.fn.snow = (options){
var $flake = $('<div class="flake" />').css({'position': 'absolute','top': '-50px'}),documentHeight = $(document).height(),documentWidth = $(document).width(),defaults = {
flakeChar : "❄",minSize : 10500null
},options = $.extend({},defaults,options);
$flake.html(options.flakeChar);
var interval = setInterval( (){
var startPositionLeft = Math.random() * documentWidth - 100 Math.random(),sizeFlake = options.minSize + Math.random() * options.maxSize,endPositionTop = documentHeight - defaults.maxSize - 40= documentHeight * 10 + Math.random() * 5000;
$flake
.clone()
.appendTo('body')
.css({
left: startPositionLeft,opacity: startOpacity,'font-size': sizeFlake,color: options.flakeColor
})
.animate({
top: endPositionTop,left: endPositionLeft,opacity: 0.2
},durationFall,'linear'() {
$(this).remove()
}
);
},options.newOn);
if (options.durationMillis) {
setTimeout(() {
clearInterval(interval);
},options.durationMillis);
}
};
})(jQuery);
$((){
$("body").snow({'durationMillis':2000}); //2s后停止生成雪花
})
* @params flakeChar - 实现雪花图案的html字符
* @params minSize - 雪花的最小尺寸
* @params maxSize - 雪花的最大尺寸
* @params newOn - 雪花出现的频率
* @params flakeColors - 雪花颜色
* @params durationMillis - 多少毫米后停止生成雪花
* @example $.fn.snow({ maxSize: 200,newOn: 1000 });