diff --git a/touch-support.js b/touch-support.js new file mode 100644 index 0000000..ec6ead4 --- /dev/null +++ b/touch-support.js @@ -0,0 +1,27 @@ +// Reference: https://www.delftstack.com/howto/javascript/detect-finger-swipe-events-in-javascript/ + +window.addEventListener('load', () => { + document.body.addEventListener('touchstart', onTouchStart); + document.body.addEventListener('touchmove', onTouchMove); + document.body.addEventListener('touchend', onTouchEnd); +}) + +var startX, startY, moveX, moveY; + +function onTouchStart(e){ + startX = e.touches[0].clientX; + startY = e.touches[0].clientY; +} + +function onTouchMove(e){ + moveX = e.touches[0].clientX; + moveY = e.touches[0].clientY; +} + +function onTouchEnd(){ + if (startY+100 < moveY){ + goToPreviousSlide(); + } else if (startY-100 > moveY){ + goToNextSlide(); + } +} \ No newline at end of file