2010-12-22 105 views
0

我有一個使用jquery的常規顏色更改,但我想要它,所以它有一個平滑的顏色變化。此時,代碼將更改懸停時鏈接的顏色,然後在刪除鼠標時將其刪除。我看過一篇教程,但它沒有解釋它,它看起來不像我當前的代碼。這是它看起來像此刻:提前與jquery褪色?

$(document).ready(function() { 
$("#link1,#link2,#link3").hover(function() { 
$(this).addClass("red"); 
},function(){ 
$(this).removeClass("red"); }); }); 

感謝

回答

2

你會使用.animate(),像這樣:

$(document).ready(function() { 
    $("#link1,#link2,#link3").hover(function() { 
    $(this).stop().animate({ color: "#990000" }); 
    },function(){ 
    $(this).stop().animate({ color: "#FFFFFF" }); 
    }); 
}); 

不過請注意,你需要無論是color plugin,或jQuery UI包括彩色動畫的工作。

+0

非常感謝,我用這個插件http://plugins.jquery.com/node/467/release,一切都很好 – Jake 2010-12-22 18:48:43

0

這裏是不使用額外的jQuery插件的簡便方法。實際上,這主要是用css完成的。使2個div彼此重疊並淡出最上面的一個。像這樣:http://jsfiddle.net/Jny9x/