From dee56c75b7725d86a667a66ecfce47812e74b0fa Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 30 Aug 2018 16:55:28 +0800 Subject: [PATCH] [bugfix] Swipe: wrong position (#1723) --- packages/mixins/touch.js | 14 +++++++++----- packages/swipe/index.vue | 15 ++++----------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/packages/mixins/touch.js b/packages/mixins/touch.js index 2b8b223d9..5d9e81ddc 100644 --- a/packages/mixins/touch.js +++ b/packages/mixins/touch.js @@ -1,11 +1,7 @@ export default { methods: { touchStart(event) { - this.direction = ''; - this.deltaX = 0; - this.deltaY = 0; - this.offsetX = 0; - this.offsetY = 0; + this.resetTouchStatus(); this.startX = event.touches[0].clientX; this.startY = event.touches[0].clientY; }, @@ -17,6 +13,14 @@ export default { this.offsetX = Math.abs(this.deltaX); this.offsetY = Math.abs(this.deltaY); this.direction = this.offsetX > this.offsetY ? 'horizontal' : this.offsetX < this.offsetY ? 'vertical' : ''; + }, + + resetTouchStatus() { + this.direction = ''; + this.deltaX = 0; + this.deltaY = 0; + this.offsetX = 0; + this.offsetY = 0; } } }; diff --git a/packages/swipe/index.vue b/packages/swipe/index.vue index 885311289..bcfad6095 100644 --- a/packages/swipe/index.vue +++ b/packages/swipe/index.vue @@ -211,21 +211,13 @@ export default create({ return; } + swipes[0].offset = (atLast && (delta < 0 || move > 0)) ? trackSize : 0; + swipes[count - 1].offset = (atFirst && (delta > 0 || move < 0)) ? -trackSize : 0; + if (move && active + move >= -1 && active + move <= count) { - if (active === -1) { - swipes[count - 1].offset = 0; - } - swipes[0].offset = atLast && move > 0 ? trackSize : 0; - this.active += move; } - if (atFirst) { - swipes[count - 1].offset = delta > 0 || move < 0 ? -trackSize : 0; - } else if (atLast) { - swipes[0].offset = delta < 0 || move > 0 ? trackSize : 0; - } - this.offset = offset - this.active * this.size; }, @@ -258,6 +250,7 @@ export default create({ this.clear(); this.timer = setTimeout(() => { this.swiping = true; + this.resetTouchStatus(); this.correctPosition(); setTimeout(() => {