CSS3解决方案
这是我的 0.2 美元。
使用 CSS3 和一点 jQuery?
HTML:
<span class="cash_warn"> <!-- removed inline style-->
text
</span>
CSS:
span.cash_warn{
color: transparent; /*set to transparent*/
text-shadow: 0 0 0 #fff; /*we concentrate the text shadow*/
-webkit-transition: all 2s ease-in-out;
-moz-transition: all 2s ease-in-out;
-o-transition: all 2s ease-in-out;
-ms-transition: all 2s ease-in-out;
transition: all 2s ease-in-out;
}
span.go_animate{ /*this will be added by JS*/
text-shadow: 0px 0px 0px #f00;
}
最后:
var textInt = setTimeout (function(){
$('span.cash_warn').addClass('go_animate');
},1000); // after one second ... add the 'go_animate' class
XBrowser 解决方案
如果您想要一个跨浏览器解决方案 - 我们可以做一个很好的技巧:
我们可以使用复制该元素.clone()
,
获取它的位置,
淡出原始元素并淡入克隆。:)
干得好:
$('.cash_warn').each(function(){
var spanPos = $(this).position();
$(this)
.fadeTo(1500,0) // fadeOut original
.clone() // clone it
.appendTo($(this).parent()) // append to parent element
.addClass('spanClone') // add a class if you need it for (CSS).
.hide() // hide the clone
.css({position:'absolute', left:spanPos.left, top: spanPos.top, color: 'red'}) // you don't need 'color' and 'position' if you have defined that already in the CSS for .spanClone
.fadeTo(1500,1); // after positions are set... fade it in!
});