Skip to content

Commit 4cc2ca7

Browse files
committed
reverse movement cancels gesture
1 parent ed98cda commit 4cc2ca7

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/js/jquery.swipebox.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@
288288
var $this = this,
289289
hDistance = null,
290290
vDistance = null,
291+
hDistanceLast = null,
292+
vDistanceLast = null,
291293
vSwipe = false,
292294
hSwipe = false,
293295
hSwipMinDistance = 50,
@@ -379,6 +381,12 @@
379381
'transition' : 'transform 0.4s ease'
380382
});
381383

384+
endCoords = event.originalEvent.targetTouches[0];
385+
386+
vDistanceLast = vDistance;
387+
vDistance = endCoords.pageY - startCoords.pageY;
388+
389+
hDistanceLast = hDistance;
382390
hDistance = endCoords.pageX - startCoords.pageX;
383391
hDistancePercent = hDistance*100/winWidth;
384392

@@ -392,7 +400,7 @@
392400
});
393401

394402
if ( vSwipe ) {
395-
if ( slider.css( 'opacity' ) <= 0.5) {
403+
if ( slider.css( 'opacity' ) <= 0.5 && abs(vDistance) >= abs(vDistanceLast)) {
396404
var vOffset = vDistance > 0 ? slider.height() : - slider.height();
397405
slider.animate( { top: vOffset + 'px', 'opacity': 0 },
398406
300,
@@ -406,10 +414,10 @@
406414
vSwipe = false;
407415
return;
408416
} else if ( hSwipe ) {
409-
if( hDistance >= hSwipMinDistance ) {
417+
if( hDistance >= hSwipMinDistance && hDistance >= hDistanceLast) {
410418
// swipeLeft
411419
$this.getPrev();
412-
} else if ( hDistance <= - hSwipMinDistance ) {
420+
} else if ( hDistance <= - hSwipMinDistance && hDistance <= hDistanceLast) {
413421
// swipeRight
414422
$this.getNext();
415423
}

0 commit comments

Comments
 (0)