Skip to content

Commit

Permalink
fix(thumbs): improve thumbs with slidesPerGroup
Browse files Browse the repository at this point in the history
fixes #3704
fixes #4007
fixes #4615
fixes #4208
  • Loading branch information
nolimits4web committed May 28, 2021
1 parent a429671 commit b2b31b3
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/components/thumbs/thumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,18 @@ const Thumbs = {
.nextAll(`[data-swiper-slide-index="${swiper.realIndex}"]`)
.eq(0)
.index();
if (typeof prevThumbsIndex === 'undefined') newThumbsIndex = nextThumbsIndex;
else if (typeof nextThumbsIndex === 'undefined') newThumbsIndex = prevThumbsIndex;
else if (nextThumbsIndex - currentThumbsIndex === currentThumbsIndex - prevThumbsIndex)
newThumbsIndex = currentThumbsIndex;
else if (nextThumbsIndex - currentThumbsIndex < currentThumbsIndex - prevThumbsIndex)
if (typeof prevThumbsIndex === 'undefined') {
newThumbsIndex = nextThumbsIndex;
else newThumbsIndex = prevThumbsIndex;
} else if (typeof nextThumbsIndex === 'undefined') {
newThumbsIndex = prevThumbsIndex;
} else if (nextThumbsIndex - currentThumbsIndex === currentThumbsIndex - prevThumbsIndex) {
newThumbsIndex =
thumbsSwiper.params.slidesPerGroup > 1 ? nextThumbsIndex : currentThumbsIndex;
} else if (nextThumbsIndex - currentThumbsIndex < currentThumbsIndex - prevThumbsIndex) {
newThumbsIndex = nextThumbsIndex;
} else {
newThumbsIndex = prevThumbsIndex;
}
direction = swiper.activeIndex > swiper.previousIndex ? 'next' : 'prev';
} else {
newThumbsIndex = swiper.realIndex;
Expand All @@ -136,8 +141,11 @@ const Thumbs = {
} else {
newThumbsIndex = newThumbsIndex + Math.floor(slidesPerView / 2) - 1;
}
} else if (newThumbsIndex > currentThumbsIndex) {
newThumbsIndex = newThumbsIndex - slidesPerView + 1;
} else if (
newThumbsIndex > currentThumbsIndex &&
thumbsSwiper.params.slidesPerGroup === 1
) {
// newThumbsIndex = newThumbsIndex - slidesPerView + 1;
}
thumbsSwiper.slideTo(newThumbsIndex, initial ? 0 : undefined);
}
Expand Down

0 comments on commit b2b31b3

Please sign in to comment.