From 015af75afbf30e39779ca20c659a021af138fbd5 Mon Sep 17 00:00:00 2001 From: Jade Geels Date: Thu, 25 May 2023 10:09:17 +0200 Subject: [PATCH] Slider autoplay bounce prop (#267) --- resources/js/components/Elements/Slider.vue | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/resources/js/components/Elements/Slider.vue b/resources/js/components/Elements/Slider.vue index 315073960..c5b591b72 100644 --- a/resources/js/components/Elements/Slider.vue +++ b/resources/js/components/Elements/Slider.vue @@ -28,6 +28,10 @@ type: Boolean, default: false, }, + bounce: { + type: Boolean, + default: false, + }, stopOnHover: { type: Boolean, default: true, @@ -40,6 +44,7 @@ showRight: false, mounted: false, hover: false, + direction: 1, pause: ()=>{}, resume: ()=>{} } @@ -76,9 +81,17 @@ }, autoScroll() { - let next = this.currentSlide + 1 - if (next >= this.slidesTotal) { - next = 0 + if(this.slidesTotal == 1) { + return + } + let next = this.currentSlide + this.direction + if (next >= this.slidesTotal || next < 0) { + if (this.bounce) { + this.direction = -this.direction + next = this.currentSlide + this.direction + } else { + next = 0 + } } this.navigate(next) },