我有一个这样的html代码:
<div id="buttons">
<a id="b1" href="#"><img src="http://content.captive-portal.com/campaigns/redbull/_images/b6.jpg" /></a>
<a id="b2" href="#"><img src="http://content.captive-portal.com/campaigns/redbull/_images/b6.jpg" /></a>
<a id="b3" href="#"><img src="http://content.captive-portal.com/campaigns/redbull/_images/b6.jpg" /></a>
<a id="b5" href="#"><img src="http://content.captive-portal.com/campaigns/redbull/_images/b6.jpg" /></a>
<a id="b6" href="#"><img src="http://content.captive-portal.com/campaigns/redbull/_images/b6.jpg" /></a>
<a id="b7" href="#"><img src="http://content.captive-portal.com/campaigns/redbull/_images/b6.jpg" /></a>
<a id="b8" href="#"><img src="http://content.captive-portal.com/campaigns/redbull/_images/b6.jpg" /></a>
</div>
和 jquery 喜欢这个:
$('#b1, #b2, #b3, #b4, #b5, #b6, #b7, #b8, #b9').hide();
setTimeout(function() {
$('#b1').fadeIn(500)
}, 600);
setTimeout(function() {
$('#b2').fadeIn(500)
}, 700);
setTimeout(function() {
$('#b3').fadeIn(500)
}, 800);
setTimeout(function() {
$('#b4').fadeIn(500)
}, 900);
setTimeout(function() {
$('#b5').fadeIn(500)
}, 1000);
setTimeout(function() {
$('#b6').fadeIn(500)
}, 1100);
setTimeout(function() {
$('#b7').fadeIn(500)
}, 1200);
setTimeout(function() {
$('#b8').fadeIn(500)
}, 1300);
如何自动延迟“按钮”div中所有项目的延迟,以便下一个每个项目都会延迟出现,但一个接一个?因此,不要为每个单独的项目编写 setTimeout 函数,而是执行一次,所以如果我再添加 100 个项目,它仍然可以正常工作吗?示例在这里:jsFiddle