Forked from bakura10/gist:b0647ef412eb7757fa6f0d2c74c1f145
Created
January 21, 2020 13:50
-
-
Save aaronsummers/9d9b9a526ee2da5640e764377c5c6a40 to your computer and use it in GitHub Desktop.
Fix flickety swipe on mobile touch devices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var touchingCarousel = false, | |
touchStartCoords; | |
document.body.addEventListener('touchstart', function(e) { | |
if (e.target.closest('.flickity-slider')) { | |
touchingCarousel = true; | |
} else { | |
touchingCarousel = false; | |
return; | |
} | |
touchStartCoords = { | |
x: e.touches[0].pageX, | |
y: e.touches[0].pageY | |
} | |
}); | |
document.body.addEventListener('touchmove', function(e) { | |
if (!(touchingCarousel && e.cancelable)) { | |
return; | |
} | |
var moveVector = { | |
x: e.touches[0].pageX - touchStartCoords.x, | |
y: e.touches[0].pageY - touchStartCoords.y | |
}; | |
if (Math.abs(moveVector.x) > 7) | |
e.preventDefault() | |
}, {passive: false}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment