Skip to content

Instantly share code, notes, and snippets.

@woahdae
Last active March 6, 2020 13:05
Show Gist options
  • Save woahdae/aa579f1eced44fb89e8fd1b7183d67de to your computer and use it in GitHub Desktop.
Save woahdae/aa579f1eced44fb89e8fd1b7183d67de to your computer and use it in GitHub Desktop.
Addresses Flickity bug #740 while someone figures out the next real solve
;(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