Skip to content

Commit 1e66fcc

Browse files
committed
avoid interference of hSwipe and vSwipe
1 parent 5894297 commit 1e66fcc

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/js/jquery.swipebox.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@
289289
hDistance = null,
290290
vDistance = null,
291291
vSwipe = false,
292+
hSwipe = false,
292293
hSwipMinDistance = 10,
293294
vSwipMinDistance = 50,
294295
startCoords = {},
@@ -322,7 +323,7 @@
322323
event.stopPropagation();
323324
endCoords = event.originalEvent.targetTouches[0];
324325

325-
if ( plugin.settings.closeBySwipe ) {
326+
if ( !hSwipe && plugin.settings.closeBySwipe ) {
326327
vDistance = endCoords.pageY - startCoords.pageY;
327328
if ( Math.abs( vDistance ) >= vSwipMinDistance || vSwipe ) {
328329
var opacity = 0.75 - Math.abs(vDistance) / slider.height();
@@ -335,9 +336,9 @@
335336
}
336337

337338
hDistance = endCoords.pageX - startCoords.pageX;
338-
hDistancePercent = hDistance*100/winWidth;
339+
hDistancePercent = hDistance*100/winWidth;
339340

340-
if( hDistance >= hSwipMinDistance || hDistance <= -hSwipMinDistance) {
341+
if( !hSwipe && !vSwipe && Math.abs( hDistance ) >= hSwipMinDistance) {
341342
$('#swipebox-slider').css({
342343
'-webkit-transition' : '',
343344
'-moz-transition' : '',
@@ -346,15 +347,19 @@
346347
'-ms-transition' : '',
347348
'transition' : ''
348349
});
350+
hSwipe = true;
351+
}
352+
353+
if( hSwipe ) {
354+
$('#swipebox-slider').css({
355+
'-webkit-transform' : 'translateX(' + (currentX + hDistancePercent) +'%)',
356+
'-moz-transform' : 'translateX(' + (currentX + hDistancePercent) + '%)',
357+
'-o-transform' : 'translateX(' + (currentX + hDistancePercent) + '%)',
358+
'-khtml-transform' : 'translateX(' + (currentX + hDistancePercent) + '%)',
359+
'-ms-transform' : 'translateX(' + (currentX + hDistancePercent) + '%)',
360+
'transform' : 'translateX(' + (currentX + hDistancePercent) + '%)'
361+
});
349362
}
350-
$('#swipebox-slider').css({
351-
'-webkit-transform' : 'translateX(' + (currentX + hDistancePercent) +'%)',
352-
'-moz-transform' : 'translateX(' + (currentX + hDistancePercent) + '%)',
353-
'-o-transform' : 'translateX(' + (currentX + hDistancePercent) + '%)',
354-
'-khtml-transform' : 'translateX(' + (currentX + hDistancePercent) + '%)',
355-
'-ms-transform' : 'translateX(' + (currentX + hDistancePercent) + '%)',
356-
'transform' : 'translateX(' + (currentX + hDistancePercent) + '%)'
357-
});
358363

359364

360365
} );
@@ -386,7 +391,7 @@
386391
'transform' : 'translateX(' + currentX + '%)'
387392
});
388393

389-
if ( plugin.settings.closeBySwipe ) {
394+
if ( vSwipe ) {
390395
if ( slider.css( 'opacity' ) <= 0.5) {
391396
var vOffset = vDistance > 0 ? slider.height() : - slider.height();
392397
slider.animate( { top: vOffset + 'px', 'opacity': 0 },
@@ -398,14 +403,9 @@
398403
slider.animate( { top: 0, 'opacity': 1 }, 300 );
399404
}
400405

401-
if ( vSwipe ) {
402-
vSwipe = false;
403-
return;
404-
}
405-
}
406-
407-
408-
if ( hDistance >= hSwipMinDistance ) {
406+
vSwipe = false;
407+
return;
408+
} else if ( hDistance >= hSwipMinDistance ) {
409409

410410
// swipeLeft
411411
$this.getPrev();

0 commit comments

Comments
 (0)