雪花飘落代码
程序员文章站
2022-07-05 16:00:33
(function($) { $.fn.snow = function(options) { var $flake = $('').css({ 'position': 'absolute', 'top': '-50px' }).html('❄'), documentHeight = $... ......
(function($) { $.fn.snow = function(options) { var $flake = $('<div id="flake" />').css({ 'position': 'absolute', 'top': '-50px' }).html('❄'), documentheight = $(document).height(), documentwidth = $(document).width(), defaults = { minsize: 10, maxsize: 20, newon: 2000, flakecolor: "red" }, options = $.extend({}, defaults, options); var interval = setinterval(function() { var startpositionleft = math.random() * documentwidth - 100, startopacity = 0.5 + math.random(), sizeflake = options.minsize + math.random() * options.maxsize, endpositiontop = documentheight - 40, endpositionleft = startpositionleft - 100 + math.random() * 200, durationfall = 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', function() { $(this).remove() }); }, options.newon); }; })(jquery); $.fn.snow({ minsize: 5, maxsize: 50, newon: 2000, flakecolor: 'red' });