|
114 | 114 | default: true
|
115 | 115 | },
|
116 | 116 |
|
| 117 | + slidesToScroll: { |
| 118 | + type: Number, |
| 119 | + default: 1 |
| 120 | + }, |
| 121 | +
|
| 122 | + slidesToShow: { |
| 123 | + type: Number, |
| 124 | + default: 1 |
| 125 | + }, |
| 126 | +
|
117 | 127 | speed: {
|
118 | 128 | type: Number,
|
119 | 129 | default: 300
|
|
151 | 161 | slide: 0,
|
152 | 162 | track: 0
|
153 | 163 | },
|
154 |
| - slidesToShow: 1, |
155 | 164 | defaultSettings: {
|
156 | 165 | prevArrow: this.prevArrow,
|
157 | 166 | nextArrow: this.nextArrow,
|
|
164 | 173 | pauseOnDotsHover: this.pauseOnDotsHover,
|
165 | 174 | pauseOnHover: this.pauseOnHover,
|
166 | 175 | responsive: this.responsive,
|
| 176 | + slidesToScroll: this.slidesToScroll, |
| 177 | + slidesToShow: this.slidesToShow, |
167 | 178 | speed: this.speed,
|
168 | 179 | timing: this.timing,
|
169 | 180 | unagile: this.unagile
|
|
242 | 253 | this.width = {
|
243 | 254 | document: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
|
244 | 255 | container: this.$refs.list.clientWidth,
|
245 |
| - slide: !this.settings.unagile ? this.$refs.list.clientWidth / this.slidesToShow : 'auto' |
| 256 | + slide: !this.settings.unagile ? this.$refs.list.clientWidth / this.settings.slidesToShow : 'auto' |
246 | 257 | }
|
247 | 258 |
|
248 | 259 | return this.width
|
|
304 | 315 |
|
305 | 316 | enableInfiniteMode () {
|
306 | 317 | if (!this.settings.fade && !this.$refs.list.getElementsByClassName('agile__slide--cloned')[0]) {
|
307 |
| - let firstSlide = this.$refs.track.firstChild.cloneNode(true) |
308 |
| - let lastSlide = this.$refs.track.lastChild.cloneNode(true) |
| 318 | + let slides = {} |
| 319 | + Object.assign(slides, this.slides) |
| 320 | +
|
| 321 | + for (let i = 0; i < this.settings.slidesToShow; i++) { |
| 322 | + let index = this.slidesCount + i - 1 |
| 323 | + let cloned = slides[i].cloneNode(true) |
| 324 | + cloned.classList.add('agile__slide--cloned') |
| 325 | + this.$refs.track.insertBefore(cloned, this.slides[index].nextSibling) |
| 326 | + } |
309 | 327 |
|
310 |
| - firstSlide.classList.add('agile__slide--cloned') |
311 |
| - lastSlide.classList.add('agile__slide--cloned') |
| 328 | + for (let i = this.slidesCount - 1; i > this.slidesCount - 1 - this.settings.slidesToShow; i--) { |
| 329 | + let cloned = slides[i].cloneNode(true) |
| 330 | + cloned.classList.add('agile__slide--cloned') |
| 331 | + this.$refs.track.insertBefore(cloned, this.slides[0]) |
| 332 | + } |
312 | 333 |
|
313 |
| - this.$refs.track.insertBefore(lastSlide, this.slides[0]) |
314 |
| - this.$refs.track.insertBefore(firstSlide, this.slides[this.slidesCount].nextSibling) |
| 334 | + this.countSlides() |
315 | 335 | }
|
316 |
| -
|
317 |
| - this.countSlides() |
318 | 336 | },
|
319 | 337 |
|
320 | 338 | disableInfiniteMode () {
|
|
345 | 363 |
|
346 | 364 | countSlides () {
|
347 | 365 | if (this.settings.infinite && !this.settings.fade && !this.settings.unagile) {
|
348 |
| - this.allSlidesCount = this.slidesCount + 2 |
| 366 | + this.allSlidesCount = this.slidesCount + (2 * this.settings.slidesToShow) |
349 | 367 | } else {
|
350 | 368 | this.allSlidesCount = this.slidesCount
|
351 | 369 | }
|
|
444 | 462 |
|
445 | 463 | this.transform = 0
|
446 | 464 | } else {
|
447 |
| - this.transform = n * this.width.slide |
| 465 | + let transform = n * this.width.slide |
| 466 | +
|
| 467 | + if (!this.settings.infinite && this.slidesCount - n < this.settings.slidesToShow) { |
| 468 | + transform -= this.width.slide * (this.slidesCount - n) |
| 469 | + } |
| 470 | +
|
| 471 | + this.transform = transform |
448 | 472 | }
|
449 | 473 |
|
450 | 474 | for (let i = 0; i < this.allSlidesCount; ++i) {
|
451 | 475 | this.slides[i].classList.remove('agile__slide--active')
|
452 | 476 | }
|
453 | 477 |
|
454 | 478 | if (this.settings.infinite && !this.settings.fade) {
|
455 |
| - this.transform += this.width.slide |
| 479 | + this.transform += this.width.slide * this.settings.slidesToShow |
456 | 480 | this.addActiveClass(n + 1)
|
457 | 481 | } else {
|
458 | 482 | this.addActiveClass(n)
|
|
536 | 560 |
|
537 | 561 | // Actions on document resize
|
538 | 562 | for (let i = 0; i < this.allSlidesCount; ++i) {
|
539 |
| - this.slides[i].style.width = this.width.container + 'px' |
| 563 | + this.slides[i].style.width = this.width.slide + 'px' |
540 | 564 |
|
541 | 565 | // Prepare slides for fade mode
|
542 | 566 | if (this.settings.fade && !this.settings.unagile) {
|
|
551 | 575 | this.width.track = this.width.container
|
552 | 576 | this.transform = 0
|
553 | 577 | } else {
|
554 |
| - this.width.track = this.width.container * this.allSlidesCount |
| 578 | + this.width.track = this.width.slide * this.allSlidesCount |
555 | 579 | this.goTo(this.currentSlide, false, false)
|
556 | 580 | }
|
557 | 581 | },
|
|
584 | 608 | return
|
585 | 609 | }
|
586 | 610 |
|
587 |
| - this.prevSlide() |
| 611 | + this.goToPrev() |
| 612 | + this.handleMouseUp() |
588 | 613 | }
|
589 | 614 |
|
590 | 615 | if (this.dragDistance < -1 * this.swipeDistance) {
|
591 | 616 | if (!this.settings.infinite && this.currentSlide === this.slidesCount - 1) {
|
592 | 617 | return
|
593 | 618 | }
|
594 | 619 |
|
595 |
| - this.nextSlide() |
| 620 | + this.goToNext() |
| 621 | + this.handleMouseUp() |
596 | 622 | }
|
597 |
| -
|
598 |
| - this.handleMouseUp() |
599 | 623 | }
|
600 | 624 | }
|
601 | 625 | }
|
|
661 | 685 | align-items: center;
|
662 | 686 | display: flex;
|
663 | 687 | list-style: none;
|
664 |
| - margin: 0; |
665 | 688 | padding: 0;
|
666 | 689 | white-space: nowrap;
|
667 | 690 | }
|
|
0 commit comments