0

我正在尝试使用以下代码将其淡化为白色以外的其他颜色:

$(titleName).fadeTo("slow", 0.3, function () {
    $(titleName).attr('data-marked', 'yes');
});

如何使用上面的代码将其淡化为白色以外的另一种颜色?

4

3 回答 3

3

jQuery 不能动画颜色,只有数字。jQuery UI 可以。

如果不想包含 jQuery UI,可以使用 animate() 的“step”回调。例如:

var div, intVal, color;
div = $(".title")

div .css({
        myAttr: 0
    })
    .animate({
        myAttr: 255
    }, {
        duration: 5000,
        step: function (currentVal) {
            intVal = Math.round(currentVal);
            color = "rgb(" + intVal + ",0, 0)";
            div.css("background-color", color);
        }
    });
于 2013-11-18T16:42:49.430 回答
0

尝试

$(titleName).animate({
    opacity: 0.3,
    color: 'red'
}, "slow", function () {
    $(this).attr('data-marked', 'yes');
});

演示:小提琴背景

注意:您需要使用jQuery UI / jQuery color来启用颜色动画,如字体颜色/背景颜色

于 2013-11-18T16:43:22.713 回答
0

使用 JQuery 颜色动画插件:http: //jqueryui.com/animate/

于 2014-11-07T01:20:36.473 回答