Add swipe support
This commit is contained in:
parent
24119fc714
commit
96358bf61a
27
touch-support.js
Normal file
27
touch-support.js
Normal 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();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user