欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

雪花飘落代码

程序员文章站 2022-04-09 19:03: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('&#10052;'),
            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' });