Add swipe support

This commit is contained in:
Knoch 2022-09-20 16:40:16 +02:00
parent 24119fc714
commit 96358bf61a

27
touch-support.js Normal file
View File

@ -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();
}
}