Skip to content

Commit b2b31b3

Browse files
committed
fix(thumbs): improve thumbs with slidesPerGroup
fixes #3704 fixes #4007 fixes #4615 fixes #4208
1 parent a429671 commit b2b31b3

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/components/thumbs/thumbs.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,18 @@ const Thumbs = {
110110
.nextAll(`[data-swiper-slide-index="${swiper.realIndex}"]`)
111111
.eq(0)
112112
.index();
113-
if (typeof prevThumbsIndex === 'undefined') newThumbsIndex = nextThumbsIndex;
114-
else if (typeof nextThumbsIndex === 'undefined') newThumbsIndex = prevThumbsIndex;
115-
else if (nextThumbsIndex - currentThumbsIndex === currentThumbsIndex - prevThumbsIndex)
116-
newThumbsIndex = currentThumbsIndex;
117-
else if (nextThumbsIndex - currentThumbsIndex < currentThumbsIndex - prevThumbsIndex)
113+
if (typeof prevThumbsIndex === 'undefined') {
118114
newThumbsIndex = nextThumbsIndex;
119-
else newThumbsIndex = prevThumbsIndex;
115+
} else if (typeof nextThumbsIndex === 'undefined') {
116+
newThumbsIndex = prevThumbsIndex;
117+
} else if (nextThumbsIndex - currentThumbsIndex === currentThumbsIndex - prevThumbsIndex) {
118+
newThumbsIndex =
119+
thumbsSwiper.params.slidesPerGroup > 1 ? nextThumbsIndex : currentThumbsIndex;
120+
} else if (nextThumbsIndex - currentThumbsIndex < currentThumbsIndex - prevThumbsIndex) {
121+
newThumbsIndex = nextThumbsIndex;
122+
} else {
123+
newThumbsIndex = prevThumbsIndex;
124+
}
120125
direction = swiper.activeIndex > swiper.previousIndex ? 'next' : 'prev';
121126
} else {
122127
newThumbsIndex = swiper.realIndex;
@@ -136,8 +141,11 @@ const Thumbs = {
136141
} else {
137142
newThumbsIndex = newThumbsIndex + Math.floor(slidesPerView / 2) - 1;
138143
}
139-
} else if (newThumbsIndex > currentThumbsIndex) {
140-
newThumbsIndex = newThumbsIndex - slidesPerView + 1;
144+
} else if (
145+
newThumbsIndex > currentThumbsIndex &&
146+
thumbsSwiper.params.slidesPerGroup === 1
147+
) {
148+
// newThumbsIndex = newThumbsIndex - slidesPerView + 1;
141149
}
142150
thumbsSwiper.slideTo(newThumbsIndex, initial ? 0 : undefined);
143151
}

0 commit comments

Comments
 (0)