diff --git a/playground/core/index.html b/playground/core/index.html index b7dd734ed..61424021b 100644 --- a/playground/core/index.html +++ b/playground/core/index.html @@ -58,6 +58,7 @@
+
@@ -69,9 +70,11 @@ import Swiper from 'swiper/swiper-bundle.mjs'; window.swiper = new Swiper(".swiper", { - slidesPerView: 5, - spaceBetween: 30, - loop: true, + slidesPerView: 'auto', + // spaceBetween: 30, + scrollbar: { + el: '.swiper-scrollbar', + }, pagination: { el: ".swiper-pagination", clickable: true diff --git a/src/core/slide/slideNext.mjs b/src/core/slide/slideNext.mjs index efdeda5f4..0a2616adf 100644 --- a/src/core/slide/slideNext.mjs +++ b/src/core/slide/slideNext.mjs @@ -2,7 +2,7 @@ export default function slideNext(speed = this.params.speed, runCallbacks = true, internal) { const swiper = this; const { enabled, params, animating } = swiper; - if (!enabled) return swiper; + if (!enabled || swiper.destroyed) return swiper; let perGroup = params.slidesPerGroup; if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) { perGroup = Math.max(swiper.slidesPerViewDynamic('current', true), 1); diff --git a/src/core/slide/slidePrev.mjs b/src/core/slide/slidePrev.mjs index ace6d7477..cfeac4540 100644 --- a/src/core/slide/slidePrev.mjs +++ b/src/core/slide/slidePrev.mjs @@ -2,7 +2,7 @@ export default function slidePrev(speed = this.params.speed, runCallbacks = true, internal) { const swiper = this; const { params, snapGrid, slidesGrid, rtlTranslate, enabled, animating } = swiper; - if (!enabled) return swiper; + if (!enabled || swiper.destroyed) return swiper; const isVirtual = swiper.virtual && params.virtual.enabled; if (params.loop) { diff --git a/src/core/slide/slideReset.mjs b/src/core/slide/slideReset.mjs index d9756236f..52974b655 100644 --- a/src/core/slide/slideReset.mjs +++ b/src/core/slide/slideReset.mjs @@ -1,5 +1,6 @@ /* eslint no-unused-vars: "off" */ export default function slideReset(speed = this.params.speed, runCallbacks = true, internal) { const swiper = this; + if (swiper.destroyed) return; return swiper.slideTo(swiper.activeIndex, speed, runCallbacks, internal); } diff --git a/src/core/slide/slideTo.mjs b/src/core/slide/slideTo.mjs index 66b6fb3a0..937fff202 100644 --- a/src/core/slide/slideTo.mjs +++ b/src/core/slide/slideTo.mjs @@ -12,6 +12,7 @@ export default function slideTo( } const swiper = this; + let slideIndex = index; if (slideIndex < 0) slideIndex = 0; @@ -28,7 +29,8 @@ export default function slideTo( if ( (swiper.animating && params.preventInteractionOnTransition) || - (!enabled && !internal && !initial) + (!enabled && !internal && !initial) || + swiper.destroyed ) { return false; } diff --git a/src/core/slide/slideToClickedSlide.mjs b/src/core/slide/slideToClickedSlide.mjs index 83dbdfc72..c8a34d2c8 100644 --- a/src/core/slide/slideToClickedSlide.mjs +++ b/src/core/slide/slideToClickedSlide.mjs @@ -2,6 +2,7 @@ import { elementChildren, nextTick } from '../../shared/utils.mjs'; export default function slideToClickedSlide() { const swiper = this; + if (swiper.destroyed) return; const { params, slidesEl } = swiper; const slidesPerView = diff --git a/src/core/slide/slideToClosest.mjs b/src/core/slide/slideToClosest.mjs index e787c2333..fe427a54c 100644 --- a/src/core/slide/slideToClosest.mjs +++ b/src/core/slide/slideToClosest.mjs @@ -6,6 +6,7 @@ export default function slideToClosest( threshold = 0.5, ) { const swiper = this; + if (swiper.destroyed) return; let index = swiper.activeIndex; const skip = Math.min(swiper.params.slidesPerGroupSkip, index); const snapIndex = skip + Math.floor((index - skip) / swiper.params.slidesPerGroup); diff --git a/src/core/slide/slideToLoop.mjs b/src/core/slide/slideToLoop.mjs index 797eb11f1..e20e713e1 100644 --- a/src/core/slide/slideToLoop.mjs +++ b/src/core/slide/slideToLoop.mjs @@ -10,6 +10,7 @@ export default function slideToLoop( index = indexAsNumber; } const swiper = this; + if (swiper.destroyed) return; const gridEnabled = swiper.grid && swiper.params.grid && swiper.params.grid.rows > 1; let newIndex = index; if (swiper.params.loop) {