当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 雪花飘落代码

雪花飘落代码

2019年02月27日  | 移动技术网IT编程  | 我要评论
(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' });

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网