From 1b076d95750fc36ac6e9392c11a394231258113e Mon Sep 17 00:00:00 2001 From: Vladimir Kharlampidi Date: Tue, 17 Jan 2023 10:53:02 +0300 Subject: [PATCH] feat(core): add loopedSlides parameter --- src/core/defaults.js | 1 + src/core/loop/loopFix.js | 2 +- src/types/swiper-options.d.ts | 7 +++++++ src/vue/swiper-vue.d.ts | 4 ++++ src/vue/swiper.js | 1 + 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/core/defaults.js b/src/core/defaults.js index 11362ebeb..cabb296ce 100644 --- a/src/core/defaults.js +++ b/src/core/defaults.js @@ -98,6 +98,7 @@ export default { // loop loop: false, + loopedSlides: null, // rewind rewind: false, diff --git a/src/core/loop/loopFix.js b/src/core/loop/loopFix.js index 399cfcd28..e14ee5bd1 100644 --- a/src/core/loop/loopFix.js +++ b/src/core/loop/loopFix.js @@ -37,7 +37,7 @@ export default function loopFix({ params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(parseFloat(params.slidesPerView, 10)); - let loopedSlides = slidesPerView; + let loopedSlides = params.loopedSlides || slidesPerView; if (loopedSlides % params.slidesPerGroup !== 0) { loopedSlides += params.slidesPerGroup - (loopedSlides % params.slidesPerGroup); } diff --git a/src/types/swiper-options.d.ts b/src/types/swiper-options.d.ts index e8ae77af1..180bbb075 100644 --- a/src/types/swiper-options.d.ts +++ b/src/types/swiper-options.d.ts @@ -587,6 +587,13 @@ export interface SwiperOptions { */ loop?: boolean; + /** + * Defines how many slides before end/beginning it should rearrange (loop) slides. If not specified, defaults to `slidesPerView` + * + * @default null + */ + loopedSlides?: number | null; + /** * Set to `true` to enable "rewind" mode. When enabled, clicking "next" navigation button (or calling `.slideNext()`) when on last slide will slide back to the first slide. Clicking "prev" navigation button (or calling `.slidePrev()`) when on first slide will slide forward to the last slide. * diff --git a/src/vue/swiper-vue.d.ts b/src/vue/swiper-vue.d.ts index 4bcd6c50f..1fdf31c85 100644 --- a/src/vue/swiper-vue.d.ts +++ b/src/vue/swiper-vue.d.ts @@ -248,6 +248,10 @@ declare const Swiper: DefineComponent< default: undefined; }; loop: { type: BooleanConstructor; default: undefined }; + loopedSlides: { + type: NumberConstructor; + default: undefined; + }; rewind: { type: BooleanConstructor; default: undefined }; allowSlidePrev: { type: BooleanConstructor; diff --git a/src/vue/swiper.js b/src/vue/swiper.js index 4b56cf9c9..05b4722b9 100644 --- a/src/vue/swiper.js +++ b/src/vue/swiper.js @@ -86,6 +86,7 @@ const Swiper = { preventClicksPropagation: { type: Boolean, default: undefined }, slideToClickedSlide: { type: Boolean, default: undefined }, loop: { type: Boolean, default: undefined }, + loopedSlides: { type: Number, default: undefined }, rewind: { type: Boolean, default: undefined }, allowSlidePrev: { type: Boolean, default: undefined }, allowSlideNext: { type: Boolean, default: undefined },