diff --git a/src/swipeview.js b/src/swipeview.js index 2546ee0..798ade8 100644 --- a/src/swipeview.js +++ b/src/swipeview.js @@ -275,7 +275,9 @@ var SwipeView = (function(){ this.moved = true; this.pointX = point.pageX; this.pointY = point.pageY; - this.directionX = deltaX > 0 ? 1 : deltaX < 0 ? -1 : 0; + if (deltaX !== 0) { + this.directionX = deltaX > 0 ? 1 : -1; + } this.stepsX += Math.abs(deltaX); this.stepsY += Math.abs(deltaY); @@ -318,7 +320,7 @@ var SwipeView = (function(){ if (!this.initiated) return; var point = hasTouch ? e.changedTouches[0] : e, - dist = Math.abs(point.pageX - this.startX); + dist = point.pageX - this.startX; this.initiated = false; @@ -330,8 +332,14 @@ var SwipeView = (function(){ } // Check if we exceeded the snap threshold - if (dist < this.snapThreshold) { - this.slider.style.webkitTransitionDuration = Math.floor(300 * dist / this.snapThreshold) + 'ms'; + if (Math.abs(dist) < this.snapThreshold) { + this.slider.style.webkitTransitionDuration = Math.floor(300 * Math.abs(dist) / this.snapThreshold) + 'ms'; + this.__pos(-this.page * this.pageWidth); + return; + } + // Check if swipe was cancelled by reversing swipe direction + if ((dist < 0 && this.directionX >= 0) || (dist > 0 && this.directionX <= 0)) { + this.slider.style.webkitTransitionDuration = Math.floor(300 * Math.abs(dist) / this.pageWidth) + 'ms'; this.__pos(-this.page * this.pageWidth); return; }