if (distanceY > swipeOutBounded) {
direction = $this.startY > $this.currentY ? 'top' : 'bottom';
} else {
direction = $this.startX > $this.currentX ? 'left' : 'right';
}
In which the swipeOutBounded variable is $this.options.swipeTolerance.
Shouldn't it be:
if (distanceY > distanceX) {
direction = $this.startY > $this.currentY ? 'top' : 'bottom';
} else {
direction = $this.startX > $this.currentX ? 'left' : 'right';
}
In the current code, we are prioritizing top/bottom swipes over left/right swipes. There is no need for prioritization. We can check if the swipe was a more vertical one or a more horizontal one, and make the decision based on that.
For example, if the start point, current point, and swipeTolerance are like this:
I was reviewing the swipe detection code to better understand its logic.
In this line we have:
In which the
swipeOutBounded
variable is$this.options.swipeTolerance
. Shouldn't it be:In the current code, we are prioritizing top/bottom swipes over left/right swipes. There is no need for prioritization. We can check if the swipe was a more vertical one or a more horizontal one, and make the decision based on that.
For example, if the start point, current point, and swipeTolerance are like this:
The current code will set
direction = 'bottom'
instead ofdirection = 'right'
.