今天看到博园有个人才写个网站网页下雪效果不错,分享一下,声明转载,也是为了我自己以后可以随时看
想看原载的去下面链接,谢谢合作,博主的会更精彩
引用地址:http://www.cnblogs.com/lhb25/archive/2012/12/25/jquery-snow-falling-effect.html
博主,梦想天空
例如可以传递下面这样形式的参数:
minSize
/* 雪花的最小尺寸,默认值 10 */
maxSize
/* 雪花的最小尺寸,默认值 20 */
newOn
/* 每毫秒雪花出现的频率,默认是 500 */
flakeColor
/* 雪花的颜色,默认值是白色 #FFFFFF */
例如可以传递下面这样形式的参数:
$.fn.snow({
minSize: 5,
maxSize: 50,
newOn: 1000,
flakeColor:
'#0099FF'
});
js代码如下:
1 /** 2 * jquery.snow - jQuery Snow Effect Plugin 3 * 4 * Available under MIT licence 5 * 6 * @version 1 (21. Jan 2012) 7 * @author Ivan Lazarevic 8 * @requires jQuery 9 * @see http://workshop.rs 10 * 11 * @params minSize - min size of snowflake, 10 by default 12 * @params maxSize - max size of snowflake, 20 by default 13 * @params newOn - frequency in ms of appearing of new snowflake, 500 by default 14 * @params flakeColor - color of snowflake, #FFFFFF by default 15 * @example $.fn.snow({ maxSize: 200, newOn: 1000 }); 16 */ 17 $(document).ready(function () { 18 $.fn.snow(); 19 }); 20 (function($){ 21 22 $.fn.snow = function(options){ 23 24 var $flake = $('<div id="flake" />').css({'position': 'absolute', 'top': '-50px'}).html('❄'), 25 documentHeight = $(document).height(), 26 documentWidth = $(document).width(), 27 defaults = { 28 minSize : 10, 29 maxSize : 20, 30 newOn : 500, 31 flakeColor : "#FFFFFF" 32 }, 33 options = $.extend({}, defaults, options); 34 35 36 var interval = setInterval( function(){ 37 var startPositionLeft = Math.random() * documentWidth - 100, 38 startOpacity = 0.5 + Math.random(), 39 sizeFlake = options.minSize + Math.random() * options.maxSize, 40 endPositionTop = documentHeight - 40, 41 endPositionLeft = startPositionLeft - 100 + Math.random() * 200, 42 durationFall = documentHeight * 10 + Math.random() * 5000; 43 $flake 44 .clone() 45 .appendTo('body') 46 .css( 47 { 48 left: startPositionLeft, 49 opacity: startOpacity, 50 'font-size': sizeFlake, 51 color: options.flakeColor 52 } 53 ) 54 .animate( 55 { 56 top: endPositionTop, 57 left: endPositionLeft, 58 opacity: 0.2 59 }, 60 durationFall, 61 'linear', 62 function() { 63 $(this).remove() 64 } 65 ); 66 }, options.newOn); 67 68 }; 69 70 })(jQuery);