【问题标题】:JQuery: Setting CSS gradient isn't workingJQuery:设置 CSS 渐变不起作用
【发布时间】:2014-05-23 09:21:31
【问题描述】:

EXAMPLE

我正在尝试将元素的背景设置为渐变,但它没有设置。它将style="" 添加到标记中,当我将代码直接放入firebug(我使用的是Firefox)时它可以工作。知道为什么它不工作或如何让它工作吗?

$('main > article').each(function (index) {
    var bg = $(this).css('background-color');
    var nextbg = $(this).next().css('background-color');
    if ($(this).next().length && nextbg != bg) {
        $(this).css('background', 'linear-gradient(to bottom, ' + bg + ' 0%, ' + nextbg + ' 100%);');
        console.log('linear-gradient(to bottom, ' + bg + ' 0%, ' + nextbg + ' 100%);');
        console.log('------------');
    }
});

【问题讨论】:

    标签: jquery css gradient linear-gradients


    【解决方案1】:

    只需删除“;”在你的 CSS 结束时

    ('main > article').each(function (index) {
        var bg = $(this).css('background-color');
        var nextbg = $(this).next().css('background-color');
        if ($(this).next().length && nextbg != bg) {
            $(this).css('background', 'linear-gradient(to bottom, ' + bg + ' 0%, ' + nextbg + ' 100%)');
            console.log('linear-gradient(to bottom, ' + bg + ' 0%, ' + nextbg + ' 100%);');
            console.log('------------');
        }
    });
    

    【讨论】:

    • facepalm - 谢谢!知道这一定是愚蠢的! xD
    猜你喜欢
    • 1970-01-01
    • 2014-08-29
    • 1970-01-01
    • 2012-03-07
    • 1970-01-01
    • 2013-07-30
    • 2018-12-27
    • 1970-01-01
    相关资源
    最近更新 更多