2011-05-30 94 views
3

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

$('#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> 

回答

5

动画opacity而不是background-color财产。

1

Alex是对的。你已经用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); 
    }); 
}); 
+0

@John Smith嗨朋友,尽我所知'背景颜色'或'颜色'不能动画。 – thecodeparadox 2011-05-30 08:54:57

+0

您需要*颜色*插件来为动画颜色添加动画。 – alex 2011-05-30 11:38:48