Skip to content

Commit c6bf926

Browse files
committed
Cleanup and add slideMultiple option.
1 parent 635ed6e commit c6bf926

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

src/components/VueperSlides.vue

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,8 @@ export default {
457457
// this.enableScroll()
458458
},
459459
460+
// Dragging did not pass conditions to change slide, snap back to current slide.
460461
cancelSlideChange () {
461-
// Apply transition to snap back to current slide.
462462
this.transition.currentTranslation = - (this.slides.current + (this.clones.length ? 1 : 0)) * 100
463463
},
464464
@@ -519,12 +519,26 @@ export default {
519519
}, 100)
520520
},
521521
522-
getSlideInRange (index) {
522+
getSlideInRange (index, autoPlaying) {
523523
let clone = null
524524
525+
// If infinite enabled, going out of range takes the first slide from the other end.
526+
if (this.conf.infinite && index === -1) clone = 0
527+
else if (this.conf.infinite && index === this.slides.count) clone = 1
528+
525529
// If going beyond slides count, take the modulo as next slide index.
526530
// E.g. If we want to access slide 9 and there are only 6 slides, go to slide 3.
527-
// index = index % this.slides.count
531+
let newIndex = index % this.slides.count + (index < 0 ? this.slides.count : 0)
532+
533+
if (this.conf.disableArrowsOnEdges && (index < 0 || index > this.slides.count - 1) && !autoPlaying) {
534+
newIndex = this.slides.current
535+
}
536+
537+
return { nextSlide: newIndex, clone: clone }
538+
},
539+
540+
getSlideInRange_old (index) {
541+
let clone = null
528542
529543
// If infinite enabled, going out of range takes the first slide from the other end.
530544
if (this.clones.length) {
@@ -566,19 +580,20 @@ export default {
566580
setTimeout(() => this.transition.animated = false, this.transitionSpeed)
567581
568582
// Get the next slide index and whether it's a clone.
569-
let { nextSlide, clone: nextSlideIsClone } = this.getSlideInRange(index)
583+
let { nextSlide, clone: nextSlideIsClone } = this.getSlideInRange(index, autoPlaying)
570584
571585
// Emit event. First use of `goToSlide` is while init, so should not propagate an event.
572586
if (this.isReady && !jumping) {
573587
this.emit('before-slide', true, nextSlide)
574588
589+
// Refresh clones.
575590
if (nextSlideIsClone !== null) this.cloneSlides()
576591
}
577592
578593
// Disable arrows if `disableArrowsOnEdges` is on and there is no slide to go to on that end.
579594
if (this.conf.arrows && this.conf.disableArrowsOnEdges) {
580-
this.arrowPrevDisabled = nextSlide === 0
581-
this.arrowNextDisabled = nextSlide === this.slides.count - 1
595+
this.arrowPrevDisabled = nextSlide === 0 || (this.conf.slideMultiple && nextSlide - this.conf.slideMultiple) < 0
596+
this.arrowNextDisabled = nextSlide === this.slides.count - 1 || (this.conf.slideMultiple && nextSlide + this.conf.slideMultiple) > this.slides.count - 1
582597
}
583598
584599
// Infinite sliding with cloned slides:
@@ -588,6 +603,7 @@ export default {
588603
// Same principle when going beyond first slide.
589604
if (nextSlideIsClone !== null) {// Gives clone id (0 or 1 or null).
590605
setTimeout(() => {
606+
console.log('timeout cz next slide is clone', nextSlideIsClone)
591607
// inside the callback, also check if it is not too late to apply next slide
592608
// (user may have slid fast multiple times) if so cancel callback.
593609
let passedCloneBackward = index === -1 && this.slides.current !== this.slides.count - 1
@@ -597,8 +613,9 @@ export default {
597613
if (!tooLateToSetTimeout) {
598614
this.transition.speed = 0
599615
this.goToSlide(nextSlideIsClone ? 0 : this.slides.count - 1, { animation: false, jumping: true })
600-
setTimeout(() => this.transition.speed = this.conf.transitionSpeed, 10)
616+
setTimeout(() => this.transition.speed = this.conf.transitionSpeed, 50)
601617
}
618+
else {console.log('timeout cancelled :D', nextSlideIsClone);this.transition.speed = 0}
602619
}, this.transition.speed - 50)
603620
}
604621
@@ -694,7 +711,7 @@ export default {
694711
...(this.$props.breakpoints && this.$props.breakpoints[this.breakpointsData.current] || {})
695712
}
696713
697-
if (conf.fade) {
714+
if (conf.fade || conf.disableArrowsOnEdges) {
698715
conf.infinite = false
699716
}
700717

0 commit comments

Comments
 (0)