丧心病狂的动画效果

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            html, body {
                width: 100%;
                height: 100%;
            }
            body {
                background: #464646;
                margin: 0;
                padding: 20px;
                overflow: hidden;
                -webkit-user-select: none;
                -moz-user-select: none;
                -ms-user-select: none;
                -o-user-select: none;
                user-select: none;
            }
            label {
                cursor: pointer;
            }
            #counter {
                position: absolute;
                top: 50%;
                left: 50%;
                color: #fff;
                font-size: 1.3em;
                text-align: center;
                -webkit-transform: translate(-50%, -50%);
                -ms-transform: translate(-50%, -50%);
                transform: translate(-50%, -50%);
                cursor: default;
            }
            #counter span {
                display: inline-block;
                width: 2em;
                text-align: left;
                color: #f60;
            }
            #max-count span {
                color: #ff0;
            }
            #setting {
                color: #fff;
            }
            .ripple-inner, .ripple-outer {
                position: absolute;
                width: 50px;
                height: 50px;
                border: 1px solid #87ceeb;
                border-radius: 50%;
                -webkit-transform: scale(0);
                -ms-transform: scale(0);
                transform: scale(0);
                -webkit-animation: ripple 2s ease-out;
                animation: ripple 2s ease-out;
                z-index: -1;
            }
            .ripple-inner {
                -webkit-animation-delay: .3s;
                animation-delay: .3s;
            }
            @-webkit-keyframes ripple {
                to {
                    -webkit-transform: scale(3);
                    transform: scale(3);
                    opacity: 0;
                }
            }
            @keyframes ripple {
                to {
                    -webkit-transform: scale(3);
                    transform: scale(3);
                    opacity: 0;
                }
            }
        </style>
        <script src="../web/js/jquery-1.8.3.min.js"></script>
    </head>

    <body>

        <div id="setting">
        Setting:
        <input type="checkbox" id="click" checked>
        <label for="click">Click</label>
        <input type="checkbox" id="mousemove">
        <label for="mousemove">Mousemove</label>
        <input type="checkbox" id="random">
        <label for="random">Random Color</label>
        <input type="checkbox" id="auto">
        <label for="auto">Auto</label>
    </div>
    <div id="counter">
        <h1 id="current-count">
            Current Ripples:
            <span>0</span>
        </h1>
        <h1 id="max-count">
            Max Ripples:
            <span>0</span>
        </h1>
    </div>



        <script>
(function ($) {
    var count = 0;
    var max = 0;
    var curCounter = $('#current-count span');
    var maxCounter = $('#max-count span');
    var container = $('body');
    var width = container.width();
    var height = container.height();
    var setting = {
        auto: false,
        click: true,
        mousemove: false,
        random: false
    };

    var createRipple = function (e) {
        var x = e.pageX || e.left;
        var y = e.pageY || e.top;
        var ripple = $('<div class="ripple-outer"></div><div class="ripple-inner"></div>');
        if (setting.random) {
            ripple.appendTo(container).css({
                left: x - 25,
                top: y - 25,
                borderColor: randomColor({
                    luminosity: 'light'
                })
            });
        } else {
            ripple.appendTo(container).css({
                left: x - 25,
                top: y - 25
            })
        }
        curCounter.text(++count);
        if (count > max) {
            maxCounter.text(max = count);
        }
        setTimeout(function () {
            ripple.remove();
            curCounter.text(--count);
        }, 2300);
    };

    var autoPlay = function () {
        if (setting.auto) {
            createRipple({
                left: Math.random() * width,
                top: Math.random() * height
            })
        }
        requestAnimationFrame(autoPlay);
    }
    autoPlay();

    $(document).on('change', 'input', function () {
        setting[this.id] = this.checked;
    });
    $(window).resize(function () {
        width = container.width();
        height = container.height();
    });

    container.click(function (e) {
        if (!setting.click) return;
        createRipple(e, this);
    }).mousemove(function (e) {
        if (!setting.mousemove) return;
        createRipple(e, this);
    });

})(jQuery);
        </script>
        <script>
    ;(function (root, factory) {

    // Support AMD
    if (typeof define === 'function' && define.amd) {
        define([], factory);

        // Support CommonJS
    } else if (typeof exports === 'object') {
        var randomColor = factory();

        // Support NodeJS & Component, which allow module.exports to be a function
        if (typeof module === 'object' && module && module.exports) {
            exports = module.exports = randomColor;
        }

        // Support CommonJS 1.1.1 spec
        exports.randomColor = randomColor;

        // Support vanilla script loading
    } else {
        root.randomColor = factory();
    };

}(this, function () {

    // Shared color dictionary
    var colorDictionary = {};

    // Populate the color dictionary
    loadColorBounds();

    var randomColor = function (options) {
        options = options || {};

        var H, S, B;

        // Check if we need to generate multiple colors
        if (options.count != null) {

            var totalColors = options.count,
                colors = [];

            options.count = null;

            while (totalColors > colors.length) {
                colors.push(randomColor(options));
            }

            options.count = totalColors;

            return colors;
        }

        // First we pick a hue (H)
        H = pickHue(options);

        // Then use H to determine saturation (S)
        S = pickSaturation(H, options);

        // Then use S and H to determine brightness (B).
        B = pickBrightness(H, S, options);

        // Then we return the HSB color in the desired format
        return setFormat([H, S, B], options);
    };

    function pickHue(options) {

        var hueRange = getHueRange(options.hue),
            hue = randomWithin(hueRange);

        // Instead of storing red as two seperate ranges,
        // we group them, using negative numbers
        if (hue < 0) {
            hue = 360 + hue
        }

        return hue;

    }

    function pickSaturation(hue, options) {

        if (options.luminosity === 'random') {
            return randomWithin([0, 100]);
        }

        if (options.hue === 'monochrome') {
            return 0;
        }

        var saturationRange = getSaturationRange(hue);

        var sMin = saturationRange[0],
            sMax = saturationRange[1];

        switch (options.luminosity) {

        case 'bright':
            sMin = 55;
            break;

        case 'dark':
            sMin = sMax - 10;
            break;

        case 'light':
            sMax = 55;
            break;
        }

        return randomWithin([sMin, sMax]);

    }

    function pickBrightness(H, S, options) {

        var brightness,
            bMin = getMinimumBrightness(H, S),
            bMax = 100;

        switch (options.luminosity) {

        case 'dark':
            bMax = bMin + 20;
            break;

        case 'light':
            bMin = (bMax + bMin) / 2;
            break;

        case 'random':
            bMin = 0;
            bMax = 100;
            break;
        }

        return randomWithin([bMin, bMax]);

    }

    function setFormat(hsv, options) {

        switch (options.format) {

        case 'hsvArray':
            return hsv;

        case 'hsv':
            return colorString('hsv', hsv);

        case 'rgbArray':
            return HSVtoRGB(hsv);

        case 'rgb':
            return colorString('rgb', HSVtoRGB(hsv));

        default:
            return HSVtoHex(hsv);
        }

    }

    function getMinimumBrightness(H, S) {

        var lowerBounds = getColorInfo(H).lowerBounds;

        for (var i = 0; i < lowerBounds.length - 1; i++) {

            var s1 = lowerBounds[i][0],
                v1 = lowerBounds[i][1];

            var s2 = lowerBounds[i + 1][0],
                v2 = lowerBounds[i + 1][1];

            if (S >= s1 && S <= s2) {

                var m = (v2 - v1) / (s2 - s1),
                    b = v1 - m * s1;

                return m * S + b;
            }

        }

        return 0;
    }

    function getHueRange(colorInput) {

        if (typeof parseInt(colorInput) === 'number') {

            var number = parseInt(colorInput);

            if (number < 360 && number > 0) {
                return [number, number];
            }

        }

        if (typeof colorInput === 'string') {

            if (colorDictionary[colorInput]) {
                var color = colorDictionary[colorInput];
                if (color.hueRange) {
                    return color.hueRange
                }
            }
        }

        return [0, 360];

    }

    function getSaturationRange(hue) {
        return getColorInfo(hue).saturationRange;
    }

    function getColorInfo(hue) {

        // Maps red colors to make picking hue easier
        if (hue >= 334 && hue <= 360) {
            hue -= 360;
        }

        for (var colorName in colorDictionary) {
            var color = colorDictionary[colorName];
            if (color.hueRange &&
                hue >= color.hueRange[0] &&
                hue <= color.hueRange[1]) {
                return colorDictionary[colorName];
            }
        }
        return 'Color not found';
    }

    function randomWithin(range) {
        return Math.floor(range[0] + Math.random() * (range[1] + 1 - range[0]));
    }

    function shiftHue(h, degrees) {
        return (h + degrees) % 360;
    }

    function HSVtoHex(hsv) {

        var rgb = HSVtoRGB(hsv);

        function componentToHex(c) {
            var hex = c.toString(16);
            return hex.length == 1 ? "0" + hex : hex;
        }

        var hex = "#" + componentToHex(rgb[0]) + componentToHex(rgb[1]) + componentToHex(rgb[2]);

        return hex;

    }

    function defineColor(name, hueRange, lowerBounds) {

        var sMin = lowerBounds[0][0],
            sMax = lowerBounds[lowerBounds.length - 1][0],

            bMin = lowerBounds[lowerBounds.length - 1][1],
            bMax = lowerBounds[0][1];

        colorDictionary[name] = {
            hueRange: hueRange,
            lowerBounds: lowerBounds,
            saturationRange: [sMin, sMax],
            brightnessRange: [bMin, bMax]
        };

    }

    function loadColorBounds() {

        defineColor(
            'monochrome',
            null, [[0, 0], [100, 0]]);

        defineColor(
            'red', [-26, 18], [[20, 100], [30, 92], [40, 89], [50, 85], [60, 78], [70, 70], [80, 60], [90, 55], [100,
                    50]]);

        defineColor(
            'orange', [19, 46], [[20, 100], [30, 93], [40, 88], [50, 86], [60, 85], [70, 70], [100, 70]]);

        defineColor(
            'yellow', [47, 62], [[25, 100], [40, 94], [50, 89], [60, 86], [70, 84], [80, 82], [90, 80], [100, 75]]);

        defineColor(
            'green', [63, 178], [[30, 100], [40, 90], [50, 85], [60, 81], [70, 74], [80, 64], [90, 50], [100, 40]]);

        defineColor(
            'blue', [179, 257], [[20, 100], [30, 86], [40, 80], [50, 74], [60, 60], [70, 52], [80, 44], [90, 39], [100,
                    35]]);

        defineColor(
            'purple', [258, 282], [[20, 100], [30, 87], [40, 79], [50, 70], [60, 65], [70, 59], [80, 52], [90, 45], [
                    100, 42]]);

        defineColor(
            'pink', [283, 334], [[20, 100], [30, 90], [40, 86], [60, 84], [80, 80], [90, 75], [100, 73]]);

    }

    function HSVtoRGB(hsv) {

        // this doesn't work for the values of 0 and 360
        // here's the hacky fix
        var h = hsv[0];
        if (h === 0) {
            h = 1
        }
        if (h === 360) {
            h = 359
        }

        // Rebase the h,s,v values
        h = h / 360;
        var s = hsv[1] / 100,
            v = hsv[2] / 100;

        var h_i = Math.floor(h * 6),
            f = h * 6 - h_i,
            p = v * (1 - s),
            q = v * (1 - f * s),
            t = v * (1 - (1 - f) * s),
            r = 256,
            g = 256,
            b = 256;

        switch (h_i) {
        case 0:
            r = v, g = t, b = p;
            break;
        case 1:
            r = q, g = v, b = p;
            break;
        case 2:
            r = p, g = v, b = t;
            break;
        case 3:
            r = p, g = q, b = v;
            break;
        case 4:
            r = t, g = p, b = v;
            break;
        case 5:
            r = v, g = p, b = q;
            break;
        }
        var result = [Math.floor(r * 255), Math.floor(g * 255), Math.floor(b * 255)];
        return result;
    }

    function colorString(prefix, values) {
        return prefix + '(' + values.join(', ') + ')';
    }

    return randomColor;
}));
        </script>
    </body>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值