diff --git a/src/swipe.vue b/src/swipe.vue index 35badaf..40dad4f 100644 --- a/src/swipe.vue +++ b/src/swipe.vue @@ -39,6 +39,7 @@ background: #000; opacity: 0.2; margin: 0 3px; + cursor: pointer; } .mint-swipe-indicator.is-active { background: #fff; @@ -54,7 +55,8 @@
+ :class="{ 'is-active': $index === index }" + @click="goto($index)"> @@ -76,6 +78,7 @@ dragging: false, userScrolling: false, animating: false, + animateReady: false, index: 0, pages: [], timer: null, @@ -203,6 +206,7 @@ doAnimate(towards, options) { if (this.$children.length === 0) return; if (!options && this.$children.length < 2) return; + if (this.animateReady) return; var prevPage, nextPage, currentPage, pageWidth, offsetLeft; var speed = this.speed || 300; @@ -222,7 +226,7 @@ nextPage = pages[index + 1]; } - if (this.continuous && pages.length > 1) { + if (this.continuous && pages.length > 1 && towards !== 'goto') { if (!prevPage) { prevPage = pages[pages.length - 1]; } @@ -288,8 +292,14 @@ if (nextPage) { nextPage.style.display = ''; } + + this.setAutoPaging(); + this.animateReady = false; }; + this.clearAutoPagingTimer(); + this.animateReady = true; + setTimeout(() => { if (towards === 'next') { this.translate(currentPage, -pageWidth, speed, callback); @@ -354,6 +364,23 @@ } }, + setAutoPaging() { + if (this.auto > 0) { + this.timer = setInterval(() => { + if (!this.dragging && !this.animating) { + this.next(); + } + }, this.auto); + } + }, + + clearAutoPagingTimer() { + if (this.timer) { + clearInterval(this.timer); + this.timer = null; + } + }, + doOnTouchStart(event) { if (this.noDrag || this.disabled) return; @@ -519,10 +546,7 @@ }, destroyed() { - if (this.timer) { - clearInterval(this.timer); - this.timer = null; - } + this.clearAutoPagingTimer(); if (this.reInitTimer) { clearTimeout(this.reInitTimer); this.reInitTimer = null; @@ -532,13 +556,7 @@ mounted() { this.ready = true; - if (this.auto > 0) { - this.timer = setInterval(() => { - if (!this.dragging && !this.animating) { - this.next(); - } - }, this.auto); - } + this.setAutoPaging(); this.reInitPages();