2013-02-03 124 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需要插件。