我相信我错过了一些简单的东西,只需要一双新眼睛。我遇到的问题是,在到达最后一个类为“slide”的第一个div之后,继续返回它应该回到第一个元素,但实际上没有这样做。我只需要有人帮我审视一下,我无法弄清楚问题在哪里,提前感谢任何帮助。
以下是我创建的函数,我不想发布所有html代码,所以我添加了一个codepen链接。
$('.arrow-next').click(function() {
var currentSlide = $('.active-slide');
var nextSlide = currentSlide.next();
var currentDot = $('.active-dot');
var nextDot = currentDot.next();
if(nextSlide.length === 0) {
nextSlide = $('.slide').first();
nextDot = $('.dot').first();
}
currentSlide.fadeOut(600).removeClass('active-slide');
nextSlide.fadeIn(600).addClass('active-slide');
currentDot.removeClass('active-dot');
nextDot.addClass('active-dot');
});
这是我的 Codepen 链接:http://codepen.io/cavascript/pen/GoQdoJ。