From 62808b2b030ad7c8b91a06c86b81a8ecdafc7c28 Mon Sep 17 00:00:00 2001 From: Rijn Date: Fri, 20 Jan 2017 11:54:25 -0600 Subject: [PATCH] reset autoplay timer after trigger add prop: autoplay direction --- src/components/carousel/carousel.vue | 14 ++++++++++++-- test/routers/carousel.vue | 9 +++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/components/carousel/carousel.vue b/src/components/carousel/carousel.vue index 34f56aa..1f61de5 100644 --- a/src/components/carousel/carousel.vue +++ b/src/components/carousel/carousel.vue @@ -47,6 +47,13 @@ type: Number, default: 2000 }, + autoplayDirection: { + type: String, + default: 'left', + validator (value) { + return oneOf(value, ['left', 'right']); + } + }, easing: { type: String, default: 'ease' @@ -175,11 +182,13 @@ this.updateSlides(true, true); this.updatePos(); + this.updateOffset(); }); }, handleResize () { this.listWidth = parseInt(getStyle(this.$el, 'width')); this.updatePos(); + this.updateOffset(); }, add (offset) { let index = this.currentIndex; @@ -191,19 +200,20 @@ dotsEvent (event, n) { if (event === this.trigger && this.currentIndex !== n) { this.currentIndex = n; + // Reset autoplay timer when trigger be activated + this.setAutoplay(); } }, setAutoplay () { window.clearInterval(this.timer); if (this.autoplay) { this.timer = window.setInterval(() => { - this.add(1); + this.add(this.autoplayDirection === 'left' ? 1 : -1); }, this.autoplaySpeed); } }, updateOffset () { this.$nextTick(() => { - this.handleResize(); this.trackOffset = this.currentIndex * this.listWidth; }); } diff --git a/test/routers/carousel.vue b/test/routers/carousel.vue index 0171d80..12b8477 100644 --- a/test/routers/carousel.vue +++ b/test/routers/carousel.vue @@ -12,6 +12,13 @@ Speed +

Direction

+ + Left + Right + +
+ Switch To 0 @@ -59,6 +66,7 @@ :current-index.sync="currentIndex" :autoplay="autoplay" :autoplay-speed="autoplaySpeed" + :autoplay-direction="autoplayDirection" :dots="dots" :trigger="trigger" :arrow="arrow" @@ -185,6 +193,7 @@ currentIndex: 0, autoplay: true, autoplaySpeed: 2000, + autoplayDirection: 'left', remove: false, pushItem: [], arrow: 'hover', -- libgit2 0.21.4