2011-05-30 95 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