我正在尝试创建一个轮播,它首先显示前 7 张图像,并且在间隔中它应该显示前 7 张图像,然后将它们淡出并显示接下来的 7 张图像。
当所有图像都显示出来时,它应该重新开始并有一个无限循环。
我怎样才能解决这个问题?
HTML:
<div class='flow'>
<img src='assets/library/en/references/1.png' />
<img src='assets/library/en/references/2.png' />
<img src='assets/library/en/references/3.png' />
<img src='assets/library/en/references/4.png' />
<img src='assets/library/en/references/5.png' />
<img src='assets/library/en/references/6.png' />
<img src='assets/library/en/references/7.png' />
<img src='assets/library/en/references/8.png' />
<img src='assets/library/en/references/9.png' />
<img src='assets/library/en/references/10.png' />
<img src='assets/library/en/references/11.png' />
<img src='assets/library/en/references/12.png' />
<img src='assets/library/en/references/13.png' />
<img src='assets/library/en/references/14.png' />
<img src='assets/library/en/references/15.png' />
<img src='assets/library/en/references/16.png' />
<img src='assets/library/en/references/17.png' />
<img src='assets/library/en/references/18.png' />
<img src='assets/library/en/references/19.png' />
<img src='assets/library/en/references/20.png' />
<img src='assets/library/en/references/21.png' />
</div>
查询:
x = 21;
setInterval(function() {
if(x>=21){
x = 21;
}
x = x - 7;
y = x + 7;
setTimeout(function() {
$('.flow > img:nth-child(1n+'+y+')').fadeOut().animate({
opacity: 0
}, 500);
}, 3000);
setTimeout(function() {
$('.flow > img:nth-child(1n+'+x+')').fadeIn().animate({
opacity: 1
}, 500);
}, 3000);
}, 3000);