From 2e3f47d5fcd37707be18180f35c9955c0bcc915e Mon Sep 17 00:00:00 2001 From: Jason <5051221+gzzhanghao@users.noreply.github.com> Date: Wed, 22 Nov 2023 20:50:10 +0800 Subject: [PATCH] fix(core): swipe to last with slidesPerView: auto (#7183) * fix(core): swipe to last with slidesPerView: auto * consider loop --------- Co-authored-by: Vladimir Kharlampidi --- src/core/events/onTouchEnd.mjs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/events/onTouchEnd.mjs b/src/core/events/onTouchEnd.mjs index ee9a4a447..4c01519ce 100644 --- a/src/core/events/onTouchEnd.mjs +++ b/src/core/events/onTouchEnd.mjs @@ -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 ( @@ -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]; }