Skip to content

Commit

Permalink
fix(core): swipe to last with slidesPerView: auto (#7183)
Browse files Browse the repository at this point in the history
* fix(core): swipe to last with slidesPerView: auto

* consider loop

---------

Co-authored-by: Vladimir Kharlampidi <[email protected]>
  • Loading branch information
gzzhanghao and nolimits4web authored Nov 22, 2023
1 parent a044626 commit 2e3f47d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/core/events/onTouchEnd.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export default function onTouchEnd(event) {
}

// Find current slide
const swipeToLast = currentPos >= -swiper.maxTranslate() && !swiper.params.loop;
let stopIndex = 0;
let groupSize = swiper.slidesSizesGrid[0];
for (
Expand All @@ -117,11 +118,11 @@ export default function onTouchEnd(event) {
) {
const increment = i < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup;
if (typeof slidesGrid[i + increment] !== 'undefined') {
if (currentPos >= slidesGrid[i] && currentPos < slidesGrid[i + increment]) {
if (swipeToLast || (currentPos >= slidesGrid[i] && currentPos < slidesGrid[i + increment])) {
stopIndex = i;
groupSize = slidesGrid[i + increment] - slidesGrid[i];
}
} else if (currentPos >= slidesGrid[i]) {
} else if (swipeToLast || currentPos >= slidesGrid[i]) {
stopIndex = i;
groupSize = slidesGrid[slidesGrid.length - 1] - slidesGrid[slidesGrid.length - 2];
}
Expand Down

0 comments on commit 2e3f47d

Please sign in to comment.