【问题标题】:CSS3 Javascript Cycle GradientCSS3 Javascript 循环渐变
【发布时间】:2011-11-03 20:55:29
【问题描述】:

我希望获得某种先机/方向来实现梯度循环,类似于 Antenna 的:http://www.theantenna.net

任何帮助将不胜感激。

【问题讨论】:

    标签: javascript canvas frontend


    【解决方案1】:

    这是在提到的网站上执行颜色循环的代码:

    Module("GradientCycle", {
        bones: "<div></div>",
        noGradient: "Please use a modern browser (like Chrome, Firefox or Safari) to fully enjoy this site",
        saturation: 0.5,
        value: 1,
        angle: 120,
        loopSpeed: 50,
        webkitCSS: "-webkit-gradient(linear, left bottom, left top,color-stop(0, rgb(RGB1)),color-stop(.5, rgb(RGB2)),color-stop(1, rgb(RGB3)))",
        geckoCSS: "-moz-linear-gradient(center bottom,rgb(RGB1) 0%,rgb(RGB2) 50%,rgb(RGB3) 100%);",
        init: function() {
            this.css = this.testCSS();
            this.seed = this.hue || Math.floor(Math.random() * 360)
        },
        testCSS: function() {
            return $("html").hasClass("webkit") ? this.webkitCSS : $("html").hasClass("gecko") ? this.geckoCSS : null
        },
        setCol: function() {
            var e = (++this.seed) % 360,
                m = this.saturation,
                l = this.value,
                k = this.angle,
                j = (e + 180 + k) % 360,
                g = (e + 180 - k) % 360,
                d = hsvToRgb(e / 360, m, l),
                c = hsvToRgb(j / 360, m, l),
                b = hsvToRgb(g / 360, m, l),
                f = this.css.replace(/RGB1/, d.join(",")).replace(/RGB2/, c.join(",")).replace(/RGB3/, b.join(","));
            this.$.attr("style", "background:" + f);
            return this
        },
        start: function() {
            if (!this.css) {
                return this.$.html(this.noGradient)
            }
            this.stop();
            this.loop = setInterval($.proxy(this.setCol, this), this.loopSpeed);
            return this
        },
        stop: function() {
            clearInterval(this.loop);
            return this
        }
    });
    

    基本上归结为修改 CSS3 渐变的颜色值。

    【讨论】:

    • – 哦,谢谢。不知道如何在标题中实现这样的东西。有什么想法吗?
    猜你喜欢
    • 1970-01-01
    • 2012-08-31
    • 2011-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多