Skip to content
This repository was archived by the owner on Feb 24, 2023. It is now read-only.

Commit a1c7828

Browse files
author
Łukasz Florczak
committed
slidesToShow fixes
1 parent 2f72d89 commit a1c7828

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

src/Agile.vue

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,17 +332,33 @@
332332
let slides = {}
333333
Object.assign(slides, this.slides)
334334
335+
let x = 0
336+
335337
for (let i = 0; i < this.settings.slidesToShow + 1; i++) {
336338
let index = this.slidesCount + i - 1
337-
let cloned = slides[i].cloneNode(true)
339+
let cloned = slides[x].cloneNode(true)
338340
cloned.classList.add('agile__slide--cloned')
339341
this.$refs.track.insertBefore(cloned, this.slides[index].nextSibling)
342+
343+
x += 1
344+
345+
if (x >= this.slidesCount) {
346+
x = 0
347+
}
340348
}
341349
350+
let y = this.slidesCount - 1
351+
342352
for (let i = this.slidesCount - 1; i > this.slidesCount - 2 - this.settings.slidesToShow; i--) {
343-
let cloned = slides[i].cloneNode(true)
353+
let cloned = slides[y].cloneNode(true)
344354
cloned.classList.add('agile__slide--cloned')
345355
this.$refs.track.insertBefore(cloned, this.slides[0])
356+
357+
y -= 1
358+
359+
if (y <= 0) {
360+
y = this.slidesCount - 1
361+
}
346362
}
347363
348364
this.countSlides()
@@ -402,6 +418,10 @@
402418
let h = Math.floor(this.settings.slidesToShow / 2)
403419
404420
for (let j = i - h; j <= i + h; j++) {
421+
if (!this.settings.infinite && (j < 0 || j >= this.slidesCount - 1)) {
422+
continue
423+
}
424+
405425
this.slides[j].classList.add('agile__slide--current')
406426
}
407427
}
@@ -490,15 +510,19 @@
490510
} else {
491511
let transform = n * this.widthSlide
492512
493-
if (!this.settings.infinite && this.slidesCount - n < this.settings.slidesToShow + 1) {
494-
transform = this.widthSlide * (this.slidesCount - this.settings.slidesToShow + 1)
513+
if (!this.settings.infinite && this.slidesCount - n < this.settings.slidesToShow) {
514+
transform = this.widthSlide * (this.slidesCount - this.settings.slidesToShow)
495515
}
496516
497517
if (this.settings.centerMode) {
498-
if (this.settings.slidesToShow % 2) {
518+
if (this.settings.slidesToShow % 2 === 0) {
519+
transform -= (Math.floor(this.settings.slidesToShow / 2) - 1) * this.widthSlide
520+
521+
if (this.settings.slidesToShow >= 4) {
522+
// transform -= Math.floor(this.settings.slidesToShow / 3) * this.widthSlide
523+
}
524+
} else {
499525
transform -= Math.floor(this.settings.slidesToShow / 2) * this.widthSlide
500-
} else if (this.settings.slidesToShow >= 4) {
501-
// transform -= Math.floor(this.settings.slidesToShow / 3) * this.widthSlide
502526
}
503527
}
504528

0 commit comments

Comments
 (0)