From ae434b0a5d76fd0d2659cd2dffc27d19c1f14a9e Mon Sep 17 00:00:00 2001 From: Vladimir Kharlampidi Date: Tue, 19 Sep 2023 10:26:02 +0300 Subject: [PATCH] feat(core): make slidesPerViewDynamic public fixes #7036 --- src/core/core.mjs | 1 + src/types/swiper-class.d.ts | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/core/core.mjs b/src/core/core.mjs index 53a55ef50..e0ea3c424 100644 --- a/src/core/core.mjs +++ b/src/core/core.mjs @@ -322,6 +322,7 @@ class Swiper { const swiper = this; const { params, slides, slidesGrid, slidesSizesGrid, size: swiperSize, activeIndex } = swiper; let spv = 1; + if (typeof params.slidesPerView === 'number') return params.slidesPerView; if (params.centeredSlides) { let slideSize = slides[activeIndex] ? slides[activeIndex].swiperSlideSize : 0; diff --git a/src/types/swiper-class.d.ts b/src/types/swiper-class.d.ts index 6b2b25432..11e521834 100644 --- a/src/types/swiper-class.d.ts +++ b/src/types/swiper-class.d.ts @@ -267,6 +267,12 @@ interface Swiper extends SwiperClass { */ slideToClosest(speed?: number, runCallbacks?: boolean): void; + /** + * Get dynamically calculated amount of slides per view, useful only when slidesPerView set to `auto` + * + */ + slidesPerViewDynamic(): number; + /** * Force swiper to update its height (when autoHeight enabled) for the duration equal to * 'speed' parameter