Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aaronsummers/9d9b9a526ee2da5640e764377c5c6a40 to your computer and use it in GitHub Desktop.
Save aaronsummers/9d9b9a526ee2da5640e764377c5c6a40 to your computer and use it in GitHub Desktop.
Fix flickety swipe on mobile touch devices
(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