有没有办法用jQuery淡化和删除文本,如下:
HTML:
<div id="texts">
<span>Text 1</span>
<span>Text 2</span>
</div>
答案 0 :(得分:1)
这种循环你需要等待一个任务完成才能完成下面的动画,最好用递归函数来实现。
命名函数表达式在这里特别方便:
$(function(){
var texts = $('#texts span').hide(),
i = 0;
(function step(){
i = (i+1)%texts.length;
texts.eq(i).fadeIn(500, function(){
texts.eq(i).fadeOut(500, step)
});
})();
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="texts">
<span>Text 1</span>
<span>Text 2</span>
</div>
&#13;
答案 1 :(得分:1)
您可以创建如下的动画:
@keyframes flickerAnimation {
0% { opacity:1; }
50% { opacity:0; }
100% { opacity:1; }
}
@-o-keyframes flickerAnimation{
0% { opacity:1; }
50% { opacity:0; }
100% { opacity:1; }
}
@-moz-keyframes flickerAnimation{
0% { opacity:1; }
50% { opacity:0; }
100% { opacity:1; }
}
@-webkit-keyframes flickerAnimation{
0% { opacity:1; }
50% { opacity:0; }
100% { opacity:1; }
}
.animate-flicker {
-webkit-animation: flickerAnimation 1s infinite;
-moz-animation: flickerAnimation 1s infinite;
-o-animation: flickerAnimation 1s infinite;
animation: flickerAnimation 1s infinite;
}
<div class="animate-flicker">Loading...</div>