Skip to content

Commit 12a44fb

Browse files
committed
fix(core): correctly destroyor create loop on breakpoints
fixes #6967
1 parent 2cf3fc2 commit 12a44fb

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/core/breakpoints/setBreakpoint.mjs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ export default function setBreakpoint() {
5656
breakpointParams.direction && breakpointParams.direction !== params.direction;
5757
const needsReLoop =
5858
params.loop && (breakpointParams.slidesPerView !== params.slidesPerView || directionChanged);
59+
const wasLoop = params.loop;
5960

6061
if (directionChanged && initialized) {
6162
swiper.changeDirection();
6263
}
6364
extend(swiper.params, breakpointParams);
6465

6566
const isEnabled = swiper.params.enabled;
67+
const hasLoop = swiper.params.loop;
6668

6769
Object.assign(swiper, {
6870
allowTouchMove: swiper.params.allowTouchMove,
@@ -80,10 +82,17 @@ export default function setBreakpoint() {
8082

8183
swiper.emit('_beforeBreakpoint', breakpointParams);
8284

83-
if (needsReLoop && initialized) {
84-
swiper.loopDestroy();
85-
swiper.loopCreate(realIndex);
86-
swiper.updateSlides();
85+
if (initialized) {
86+
if (needsReLoop) {
87+
swiper.loopDestroy();
88+
swiper.loopCreate(realIndex);
89+
swiper.updateSlides();
90+
} else if (!wasLoop && hasLoop) {
91+
swiper.loopCreate(realIndex);
92+
swiper.updateSlides();
93+
} else if (wasLoop && !hasLoop) {
94+
swiper.loopDestroy();
95+
}
8796
}
8897

8998
swiper.emit('breakpoint', breakpointParams);

0 commit comments

Comments
 (0)