2013-02-03 119 views
0

我有一個span元素:jQuery的淡入淡出效果,

<span id="signInResult" style="border: 1px solid white;">html in here</span> 

當jQuery的AJAX成功火災,我想跨度立即變綠,然後漸退到默認的白色:

success: function(msg){ 
    $("#signInResult").css('border-style', 'solid'); 
    $("#signInResult").css('border-color', 'green'); 
    $("#signInResult").fadeIn(300).css('border-color', 'white').fadeIn(300); 
} 

我已經嘗試了一些fadeIn和fadeOut的變化..上面的當前版本似乎沒有做任何事情....最好的方式來做到這一點,以獲得慾望的結果?謝謝

回答

1

您可能想要使用animate。它將指定時間範圍內緩慢給定的css屬性更改爲給定值。 FadeIn/FadeOut只處理opacitydisplay

嘗試:

success:function(msg) { 
    $("#signInResult").css('border-color', '#0f0').animate({'border-color': '#fff'}, 300); 
} 

文檔:

+0

這就是金!謝謝。小的語法點共同應該是冒號:{'border-color':'#fff'}謝謝! – mandalorianwarrior

+2

請注意(除非你包含[jQueryUI](http://jqueryui.com/)(或其他顏色插件),否則'.animate()'不適用於顏色。 。 – nnnnnn

+0

好的謝謝你的提示。我有jqUI CDN ..洛杉磯的代碼已經過測試,它的工作原理。謝謝 – mandalorianwarrior

1

至於你的問題中提到,要更改邊框的顏色,動畫的顏色試試這個:

http://jsbin.com/anubin/1/edit

$(function() { 
    $("#signInResult").css('border-style', 'solid'); 
    $("#signInResult").css('border-color', 'green'); 
    $("#signInResult").hide().fadeIn(300); 

    $("#signInResult").animate({ 
     borderColor: "white", 
     width: 500 
     }, 1000); 
}); 

jquery ui需要插件。