淡入淡出和循环遍历div的最佳方法 [英] Best way to fade and loop through a set of divs
本文介绍了淡入淡出和循环遍历div的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有以下div:
<div class="a">You are funny.</div>
<div class="b">You are smart.</div>
<div class="c">You are cool.</div>
显示div.a
5秒钟,然后淡出并在div.b
中淡入5秒钟,然后到div.c
然后再回到div.a
并继续循环无限量的最佳方法是什么?时间?
What is the best way to show div.a
for 5 seconds, then fade out and fade in div.b
for 5 seconds and then to div.c
and then back to div.a
and continue looping for an infinite amount of time?
谢谢:)
推荐答案
您可以使用值数组并循环遍历它们.
You can use an array of values and loop thru them.
var div = $('div').hide(),
news = ['news1', 'news2', 'news3'],
count = 0;
function changeNews() {
div.fadeIn().delay(500).fadeOut(function() {
changeNews();
}).text(news[count++])
if (count == news.length) {
count = 0;
}
}
changeNews();
这篇关于淡入淡出和循环遍历div的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文