-
-
Save john-dave-manuel/e579bdae23ba6161e78dd85d0f862610 to your computer and use it in GitHub Desktop.
Addresses Flickity bug #740 while someone figures out the next real solve
This file contains hidden or 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('.carousel-cell')) { | |
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) > Flickity.defaults.dragThreshold) | |
e.preventDefault() | |
}, {passive: false}) | |
// Polyfill for Element.closest | |
// https://developer.mozilla.org/en-US/docs/Web/API/Element/closest | |
if (!Element.prototype.matches) { | |
Element.prototype.matches = | |
Element.prototype.msMatchesSelector || | |
Element.prototype.webkitMatchesSelector | |
} | |
if (!Element.prototype.closest) { | |
Element.prototype.closest = | |
function(s) { | |
var el = this | |
do { | |
if (el.matches(s)) return el | |
el = el.parentElement || el.parentNode | |
} while (el !== null && el.nodeType === 1) | |
return null | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment