Skip to content

Commit

Permalink
feat(core): add loopedSlides parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
nolimits4web committed Jan 17, 2023
1 parent 9e2338a commit 1b076d9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/core/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default {

// loop
loop: false,
loopedSlides: null,

// rewind
rewind: false,
Expand Down
2 changes: 1 addition & 1 deletion src/core/loop/loopFix.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 7 additions & 0 deletions src/types/swiper-options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 4 additions & 0 deletions src/vue/swiper-vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/vue/swiper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down

0 comments on commit 1b076d9

Please sign in to comment.