jQuery - 从透明到彩色的动画,没有白色闪光?

时间:2011-05-30 06:43:40

标签: jquery jquery-animate

我需要从透明到彩色动画,但是当我这样做时,我会得到一个白色闪光。我认为这是因为没有基础颜色来制作动画。我该如何解决这个问题?

$('#nav a').hover(function() {
    $(this).animate({
        'background-color' : $(this).attr('data-background'),
        'color' : $(this).attr('data-rollover')
    }, 900);
});

<a style="color:#ffff00; " data-background="#000066" data-color="#ffff00" data-rollover="#000000" href="index.php?p=1" ><span >Home</span></a>

2 个答案:

答案 0 :(得分:5)

opacity而不是background-color属性设置动画。

答案 1 :(得分:1)

亚历克斯是对的。你用opacity做到了。你可以试试这个:

$('#nav a').hover(function() {
    $(this).animate({
        'opacity': 0
    },
    1,
    function() {
        $(this).css({
            'background-color': $(this).attr('data-rollover'),
            'color': $(this).attr('data-color')
        }).animate({
            'opacity': 1
        },
        900);
    });
});
相关问题